Skip to content

Commit 1c78118

Browse files
committed
Update Quick Start
Adding Arduino code snippets.
1 parent 900e21f commit 1c78118

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

docs/quickstart.md

+51-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The example includes several serial prints to indicate success or failure. If th
7777

7878
**Code to Note**:
7979

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:
8181
```c++
8282
#ifndef STASSID
8383
#define STASSID "SSID"
@@ -94,7 +94,56 @@ The example includes several serial prints to indicate success or failure. If th
9494
#define LED_BRIGHTNESS 30
9595
```
9696
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+
```
98147

99148
## Going Further
100149

0 commit comments

Comments
 (0)