Skip to content

Commit f05bda5

Browse files
authored
Update spiffs_rest_api.ino
1 parent 086fc2d commit f05bda5

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

examples/spiffs_rest_api/spiffs_rest_api.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define DEBUG_BEGIN Serial.begin(115200)
55
#define DEBUG_PRINT(x) Serial.println(x)
66
#else
7-
#define DEBUG_PRINT(x)
7+
#define DEBUG_PRINT(x)
88
#define DEBUG_BEGIN
99
#endif
1010

@@ -13,6 +13,7 @@
1313
#include <ArduinoJson.h>
1414
#include <ESP8266WiFi.h>
1515
#include <ESP8266SSDP.h>
16+
#include <EasySSDP.h>
1617

1718
//extension of ESP8266WebServer with SPIFFS handlers built in
1819
#include <SPIFFSReadServer.h> // http://ryandowning.net/SPIFFSReadServer
@@ -38,15 +39,15 @@ String y;
3839
void setup() {
3940
DEBUG_BEGIN; //for terminal debugging
4041
DEBUG_PRINT();
41-
42+
4243
//optional code handlers to run everytime wifi is connected...
4344
persWM.onConnect([]() {
4445
DEBUG_PRINT("wifi connected");
4546
DEBUG_PRINT(WiFi.localIP());
4647
EasySSDP::begin(server, DEVICE_NAME);
4748
});
4849
//...or AP mode is started
49-
persWM.onAp([](){
50+
persWM.onAp([]() {
5051
DEBUG_PRINT("AP MODE");
5152
DEBUG_PRINT(persWM.getApSsid());
5253
});
@@ -63,21 +64,20 @@ void setup() {
6364
DEBUG_PRINT("server.on /api");
6465
if (server.hasArg("x")) {
6566
x = server.arg("x").toInt();
66-
DEBUG_PRINT(String("x: ")+x);
67+
DEBUG_PRINT(String("x: ") + x);
6768
} //if
6869
if (server.hasArg("y")) {
6970
y = server.arg("y");
70-
DEBUG_PRINT("y: "+y);
71+
DEBUG_PRINT("y: " + y);
7172
} //if
7273

7374
//build json object of program data
74-
StaticJsonBuffer<200> jsonBuffer;
75-
JsonObject &json = jsonBuffer.createObject();
75+
StaticJsonDocument<200> json;
7676
json["x"] = x;
7777
json["y"] = y;
7878

7979
char jsonchar[200];
80-
json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece
80+
serializeJson(json, jsonchar); //print to char array, takes more memory but sends in one piece
8181
server.send(200, "application/json", jsonchar);
8282

8383
}); //server.on api

0 commit comments

Comments
 (0)