MCPcopy Create free account
hub / github.com/SmingHub/Sming / onAjaxInput

Function onAjaxInput

samples/HttpServer_AJAX/app/application.cpp:45–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void onAjaxInput(HttpRequest& request, HttpResponse& response)
46{
47 JsonObjectStream* stream = new JsonObjectStream();
48 JsonObject json = stream->getRoot();
49 json["status"] = (bool)true;
50
51 String stringKey = F("StringKey");
52 String stringValue = F("StringValue");
53
54 json[stringKey] = stringValue;
55
56 for(int i = 0; i < 11; i++) {
57 String desiredString = F("sensor_") + String(i);
58 json[desiredString] = desiredString;
59 }
60
61 JsonObject gpio = json.createNestedObject("gpio");
62 for(unsigned i = 0; i < ARRAY_SIZE(inputs); ++i) {
63 gpio[String(i)] = digitalRead(inputs[i]);
64 }
65
66 response.sendDataStream(stream, MIME_JSON);
67}
68
69void onAjaxFrequency(HttpRequest& request, HttpResponse& response)
70{

Callers

nothing calls this directly

Calls 5

getRootMethod · 0.80
FFunction · 0.50
StringClass · 0.50
digitalReadFunction · 0.50
sendDataStreamMethod · 0.45

Tested by

no test coverage detected