@@ -77,7 +77,7 @@ The example includes several serial prints to indicate success or failure. If th
77
77
78
78
** Code to Note** :
79
79
80
- * WiFi Network Variables . Adjust "SSID" and "PASSWORD" to your WiFi network's ID and password:
80
+ * WiFi network variables . Adjust "SSID" and "PASSWORD" to your WiFi network's ID and password:
81
81
``` c++
82
82
#ifndef STASSID
83
83
#define STASSID "SSID"
@@ -94,7 +94,56 @@ The example includes several serial prints to indicate success or failure. If th
94
94
#define LED_BRIGHTNESS 30
95
95
```
96
96
97
- *
97
+ * Attempt to connect to WiFi network:
98
+ ```c++
99
+ multi.addAP(ssid, password);
100
+
101
+ if(multi.run() != WL_CONNECTED) {
102
+ Serial.println(F("Unable to connect to network, rebooting in 10 seconds..."));
103
+ delay(10000);
104
+ rp2040.reboot();
105
+ }
106
+
107
+ Serial.println(F("Connected to network"));
108
+ Serial.println(F("IP address: "));
109
+ Serial.println(WiFi.localIP());
110
+ ```
111
+
112
+ * Send HTTP get request:
113
+ ```c++
114
+ client.println(F(" GET /international-space-station-APIs/JSON/people-in-space.json HTTP/1.0" ));
115
+ client.println(F(" Host: corquaid.github.io" ));
116
+ client.println(F(" Connection: close" ));
117
+ ```
118
+
119
+ * Parse JSON request:
120
+ ``` c++
121
+ JsonDocument doc;
122
+ DeserializationError error = deserializeJson(doc, client);
123
+ if (error) {
124
+ Serial.print(F("deserializeJson() failed: "));
125
+ Serial.println(error.f_str());
126
+ client.stop();
127
+ return;
128
+ }
129
+ ```
130
+
131
+ * Print number & names of astronauts in space:
132
+ ```c++
133
+ int numberOfPeople = doc[F("number")];
134
+
135
+ Serial.print(F("There are "));
136
+ Serial.print(numberOfPeople);
137
+ Serial.println(F(" astronauts in space."));
138
+
139
+ for(JsonObject people_item : doc[F("people")].as<JsonArray>()) {
140
+ int people_item_id = people_item[F("id")];
141
+ const char* people_item_name = people_item[F("name")];
142
+ Serial.print(people_item_id);
143
+ Serial.print(F(": "));
144
+ Serial.println(people_item_name);
145
+ }
146
+ ```
98
147
99
148
## Going Further
100
149
0 commit comments