/* * 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 extern "C" { uint16 readvdd33(void); } //#define ESSID "wa-v101f" //#define PASSWORD "aaaaaaaaa" #define ESSID "HZSOL-WRK" #define PASSWORD "HZSOL231wpa" #define ONE_WIRE_BUS 5 ADC_MODE(ADC_VCC); //vcc read 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 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, "w_sensor="); strcat(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, ";"); } void setup() { Serial.begin(9600); 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); */ display.begin(); // initializes the display display.setBacklight(100); // set the brightness to 100 % sensors.begin(); WiFi.begin(ESSID, PASSWORD); Serial.print(WiFi.macAddress()); do_stuff(); ESP.deepSleep(59000000); } void do_stuff() { char tstr[20]; float t; int tt; char data[50]; say("hi "); float vdd = ESP.getVcc() / 1000.0; Serial.println(vdd); Serial.println(readvdd33()); sensors.requestTemperatures(); t = sensors.getTempCByIndex(0); tt = t * 100; // sprintf(tstr, "temperature: %f", t); dtostrf(t, 2, 2, tstr); say(tstr); Serial.print("temp\n"); Serial.print(t); Serial.print("\n"); Serial.print(tstr); Serial.print("\n"); display.setColonOn(true); byte rawData; 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","meteo2", data, t); Serial.println(data); if((WiFi.status() == WL_CONNECTED)) { send_data(data); Serial.println("connected"); } else { Serial.println("not connected"); } } void loop() { }