/* * 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 #define ESSID "wa-v101f" #define ONE_WIRE_BUS 5 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; } 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); // initializes the Serial connection @ 9600 baud display.begin(); // initializes the display display.setBacklight(100); // set the brightness to 100 % sensors.begin(); delay(1000); // wait 1000 ms WiFi.begin(ESSID, "aaaaaaaaa"); } void loop() { char tstr[20]; float t; int tt; char data[50]; say("hi "); 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); } else { } delay(2000); }