1 //USBtinyISP upload using programmer
5 #include <ESP8266WiFi.h>
9 bool DEBUG = true; //show more logs
10 int responseTime = 10; //communication timeout
13 unsigned long timeout;
14 char host[] = "some.host.com";
17 const char ssid[] = "SSID";
18 const char pass[] = "PASS";
25 next = millis() + 15000;
26 timeout = millis() + 5000;
28 snprintf(macstr, 18, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
30 WiFi.begin(ssid,pass);
31 WiFi.setAutoReconnect(true);
32 while (WiFi.status() != WL_CONNECTED) {
36 Serial.print("Connected, IP address: ");
37 Serial.println(WiFi.localIP());
38 Serial.println("You're connected to the network");
39 Serial.println("Booted");
45 if (((signed long)(millis() - next)) > 0) {
46 if ((WiFi.status() != WL_CONNECTED)) {
49 while (WiFi.status() != WL_CONNECTED) {
58 next = millis() + 15000;
59 timeout = millis() + 15000;
60 if (client.connect(host,8086)) {
61 lightValue = analogRead(lightPin);
62 String PostData = "light,sensor=\"" + String(macstr) + "\" value=" + String(lightValue) + "\ntemp,sensor=\"" + String(macstr) + "\" value=" + String(dht.readTemperature(true)) + "\nhumidity,sensor=\"" + String(macstr) + "\" value=" + String(dht.readHumidity());
63 client.println("POST /write?db=sensors HTTP/1.1");
64 client.print("HOST: ");
66 client.println("User-Agent: Arduino/1.0");
67 client.println("Connection: close");
68 client.println("Content-Type: application/x-www-form-urlencoded;");
69 client.print("Content-Length: ");
70 client.println(PostData.length());
72 client.println(PostData);