/* * https://github.com/bremme/arduino-tm1637 * The circuit: * connect TM1637 pin CLK to Arduino pin D4 * connect TM1637 pin DIO to Arduino pin D5 * connect TM1637 pin Vcc to Arduino pin 5V * connect TM1637 pin GND to Arduino pin GND */ #include "SevenSegmentTM1637.h" #include "SevenSegmentExtended.h" #include "SevenSegmentFun.h" #include #include #include #include #include extern "C" { uint16 readvdd33(void); } #define ONE_WIRE_BUS 5 #define REDLED 0 #define GREENLED 2 //#define DOSLEEP #define LEDBLINK ADC_MODE(ADC_VCC); //vcc read const char * essids[10]; const char * passwords[10]; const byte PIN_CLK = 12; // define CLK pin (any digital pin) const byte PIN_DIO = 14; // define DIO pin (any digital pin) SevenSegmentFun display(PIN_CLK, PIN_DIO); OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); void ledblink(int led) { #ifdef LEDBLINK digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); #endif } void list_networks() { // scan for nearby networks: Serial.println("** Scan Networks **"); int numSsid = WiFi.scanNetworks(); if (numSsid == -1) { Serial.println("Couldn't get a wifi connection"); while (true); } // print the list of networks seen: Serial.print("number of available networks:"); Serial.println(numSsid); // print the network number and name for each network found: for (int thisNet = 0; thisNet < numSsid; thisNet++) { Serial.print(thisNet); Serial.print(") "); Serial.print(WiFi.SSID(thisNet)); Serial.print("\tSignal: "); Serial.print(WiFi.RSSI(thisNet)); Serial.print(" dBm"); Serial.print("\tEncryption: "); printEncryptionType(WiFi.encryptionType(thisNet)); } } void printEncryptionType(int thisType) { // read the encryption type and print out the name: switch (thisType) { case ENC_TYPE_WEP: Serial.println("WEP"); break; case ENC_TYPE_TKIP: Serial.println("WPA"); break; case ENC_TYPE_CCMP: Serial.println("WPA2"); break; case ENC_TYPE_NONE: Serial.println("None"); break; case ENC_TYPE_AUTO: Serial.println("Auto"); break; } } void say(char* str) { display.print(str); delay(500); } char * xstrcpy(char * dest, String src) { int i; for(i = 0; i < src.length(); i++) { dest[i] = src[i]; } dest[i] = '\0'; return dest; } char * get_ip() { char ip[16]; xstrcpy(ip, WiFi.localIP().toString()); return ip; } void turnOff(int pin) { pinMode(pin, OUTPUT); digitalWrite(pin, 1); } 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 create_line(char * type, char * sn, char * data, float value) { char buf[12]; strcpy(data, "type:METEO,"); strcat(data, "sn:"); strcat(data, sn); strcat(data, ","); strcat(data, "temp:"); dtostrf(value, 5, 2, buf); strcat(data, buf); strcat(data, ",ip:"); strcat(data, get_ip()); strcat(data, ";"); } char * get_wifi_status(int m) { switch (m) { case 0: return "WL_IDLE_STATUS"; case 1: return "WL_NO_SSID_AVAIL"; case 2: return "WL_SCAN_COMPLETED"; case 3: return "WL_CONNECTED"; case 4: return "WL_CONNECT_FAILED"; case 5: return "WL_CONNECTION_LOST"; case 6: return "WL_DISCONNECTED"; } } void find_wifi() { int i,ii; for (i = 0; i < 4; i++) { Serial.print("trying "); Serial.print(essids[i]); Serial.print(":"); Serial.println(passwords[i]); WiFi.begin(essids[i], passwords[i]); for (ii = 0; ii < 100; ii++) { Serial.println(get_wifi_status(WiFi.status())); delay(20); } if((WiFi.waitForConnectResult() == WL_CONNECTED)) { Serial.println("FOUND"); return; } else { Serial.println("NOPE"); WiFi.disconnect(); } } Serial.println("couldn't find a shit"); } void turn_off_pins() { turnOff(10); turnOff(9); //turnOff(16); //turnOff(5); turnOff(4); turnOff(0); turnOff(2); turnOff(14); turnOff(12); //turnOff(13); //turnOff(15); //turnOff(3); //turnOff(1); } void infoled_setup() { digitalWrite(GREENLED, LOW); digitalWrite(REDLED, LOW); } void wifi_essids_setup() { essids[0] = "wa-v101f"; essids[1] = "HZSOL-WRK"; essids[2] = "waredmi"; essids[3] = "3GWiFi_55357C"; passwords[0] = "aaaaaaaaa"; passwords[1] = "HZSOL231wpa"; passwords[2] = "aaaaaaaaa"; passwords[3] = "1245678"; } void setup() { Serial.begin(9600); wifi_essids_setup(); turn_off_pins(); infoled_setup(); display.begin(); display.setBacklight(100); sensors.begin(); // WiFi.persistent(false); //disables the storage to flash. WiFi.mode(WIFI_STA); if(WiFi.status() != WL_CONNECTED) { WiFi.begin(); } delay(100); if(WiFi.status() != WL_CONNECTED) { Serial.println("start: not connected"); find_wifi(); } else { Serial.println("start: connected"); } Serial.println(WiFi.macAddress()); //list_networks(); delay(1000); do_stuff(); #ifdes DOSLEEP ESP.deepSleep(59000000); #endif } void do_stuff() { char tstr[20]; float t; int tt; char data[50]; say("----"); float vdd = ESP.getVcc() / 1000.0; dtostrf(vdd, 2, 2, tstr); say("voltage:"); say(tstr); // Serial.println(readvdd33()); delay(500); say("----"); say("temperature"); sensors.requestTemperatures(); t = sensors.getTempCByIndex(0); // dtostrf(t, 2, 2, tstr); // say(tstr); display.setColonOn(true); byte rawData; tt = t * 100; display.print(tt); // display degree symbol on position 3 plus set lower colon rawData = B11100011; display.printRaw(rawData, 3); delay(1000); display.setColonOn(false); create_line("x","meteotest", data, t); Serial.println(data); if((WiFi.status() == WL_CONNECTED)) { //send_data(data); Serial.print("connected to "); Serial.println(WiFi.SSID()); ledblink(GREENLED); } else { Serial.println("not connected"); ledblink(REDLED); } } void loop() { do_stuff(); }