#include #include #include #include #include #include #include #include "DHT.h" #define ESSID "wa-v101f" //#define ESSID "waredmi" #define REDLED 12 #define GREENLED 14 #define DHTPIN 4 #define DHTTYPE DHT22 //OneWire oneWire(4); OneWire oneWire2(5); //DallasTemperature sensorin(&oneWire); DallasTemperature sensorout(&oneWire2); DHT dht(DHTPIN, DHTTYPE); const char * essids[10]; const char * passwords[10]; void wifi_essids_setup() { essids[0] = "wa-v101f"; essids[1] = "HZSOL-WRK"; essids[2] = "waredmi"; essids[3] = "walley"; essids[4] = "grezl"; passwords[0] = "aaaaaaaaa"; passwords[1] = "HZSOL231wpa"; passwords[2] = "aaaaaaaaa"; passwords[3] = "aaaaaaaaa"; passwords[4] = "aaaaaaaaa"; } int find_wifi() { int i,ii; Serial.println("* WIFI *"); for (i = 0; i < 5; i++) { Serial.print("trying "); Serial.print(essids[i]); Serial.print(":"); Serial.println(passwords[i]); WiFi.begin(essids[i], passwords[i]); if((WiFi.waitForConnectResult() == WL_CONNECTED)) { Serial.println("FOUND"); return 1; } else { Serial.println("NOPE"); WiFi.disconnect(); } } Serial.println("couldn't find a shit"); return 0; } int send_data(char * data) { HTTPClient http; Serial.print("[HTTP] begin\n"); http.begin("http://grezl.eu/wiot/v1/sensor"); Serial.print("[HTTP] POST\n"); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); int http_code = http.POST(data); //http.writeToStream(&Serial); Serial.printf("[HTTP] http code: %d\n", http_code); if (http_code > 0) { /* if (http_code == HTTP_CODE_OK) { String payload = http.getString(); Serial.println(payload); } */ } else { Serial.printf("[HTTP] failed, error: %s\n", http.errorToString(http_code).c_str()); } http.end(); return http_code; } void ledblink(int led) { digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); } void create_line(char * type, char * sn, char * data, float value, float value2) { char buf[12]; strcpy(data, "w_sensor="); strcat(data, "type:DS,"); strcat(data, "sn:"); strcat(data, sn); strcat(data, ","); strcat(data, "temp:"); dtostrf(value, 5, 2, buf); strcat(data, buf); if (value2 > -127) { strcat(data, ","); strcat(data, "hum:"); dtostrf(value2, 5, 2, buf); strcat(data, buf); } strcat(data, ";"); } void setup() { pinMode(GREENLED, OUTPUT); pinMode(REDLED, OUTPUT); wifi_essids_setup(); ledblink(GREENLED); ledblink(REDLED); Serial.begin(115200); // Serial.setDebugOutput(true); Serial.println("Start"); // sensorin.begin(); sensorout.begin(); // WiFi.persistent(false); WiFi.mode(WIFI_STA); find_wifi(); //WiFi.begin(ESSID, "aaaaaaaaa"); } void loop() { float tempin,tempout; char datain[60]; char dataout[60]; float dht_h; float dht_t; Serial.println("Requesting temperatures... "); dht_h = dht.readHumidity(); dht_t = dht.readTemperature(); // sensorin.requestTemperatures(); sensorout.requestTemperatures(); Serial.println(dht_h); Serial.println(dht_t); // Serial.println(sensorin.getTempCByIndex(0)); Serial.println(sensorout.getTempCByIndex(0)); Serial.println("DONE "); // tempin = sensorin.getTempCByIndex(0); tempout = sensorout.getTempCByIndex(0); // create_line("x","ds0", datain, tempin); create_line("x","ds0", datain, dht_t, dht_h); create_line("x","ds1", dataout, tempout, -127.0); Serial.println(datain); Serial.println(dataout); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if((WiFi.status() == WL_CONNECTED)) { send_data(datain); send_data(dataout); ledblink(GREENLED); } else { Serial.println("Not connected."); ledblink(REDLED); } delay(20000); //delay(1000); }