void RestDhtApi::dht(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[32]; char value[32]; //server.httpSuccess("application/json"); server.httpSuccess(); if (type != WebServer::GET) return; if (strlen(url_tail)) { DHT dht; while (strlen(url_tail)) { rc = server.nextURLparam(&url_tail, name, 32, value, 32); String param = String(name); if (param == "pin") { String vl = value; int v = atoi(vl.c_str()); dht.setup(v); dht.getMinimumSamplingPeriod(); double hum = dht.getHumidity(); double tempC = dht.getTemperature(); double tempF = dht.toFahrenheit(tempC); Serial.println(v); Serial.print(dht.getStatusString()); Serial.print(" - "); Serial.print(hum, 1); Serial.print("% - "); Serial.print(tempC, 1); Serial.print("C - "); Serial.print(tempF, 1); Serial.println("F"); } } } }
void RestApi::put(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[32]; char value[32]; //server.httpSuccess("application/json"); server.httpSuccess(); if (type != WebServer::PUT) return; if (strlen(url_tail)) { while (strlen(url_tail)) { rc = server.nextURLparam(&url_tail, name, 32, value, 32); String param = String(name); String vl = value; int v = atoi(vl.c_str()); if (v >= 0) { String t = name; char tp = t.charAt(0); String p = t.substring(1, 32); int pin = atoi(p.c_str()); if (tp == 'd') { digitalWrite(pin, v); } else { analogWrite(pin, v); } Serial.print(pin + ":"); Serial.println(v); } } } }
void RestApi::get(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) { URLPARAM_RESULT rc; char name[32]; char value[32]; //server.httpSuccess("application/json"); server.httpSuccess(); if (type != WebServer::GET) return; if (strlen(url_tail)) { while (strlen(url_tail)) { rc = server.nextURLparam(&url_tail, name, 32, value, 32); String param = String(name); if (param == "pin") { String t = value; char tp = t.charAt(0); String p = t.substring(1, 32); int pin = atoi(p.c_str()); if (tp == 'd') { Serial.println(digitalRead(pin)); } else { Serial.println(analogRead(pin)); } } } } }