-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathEmoncms.ino
68 lines (56 loc) · 1.38 KB
/
Emoncms.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Emoncms.h"
WiFiClient client;
#define UPDATE_PERIOD 60000
#define TIMEOUT_PERIOD 1000
const char* dataHost = "emoncms.org";
const char* apiKey = "9a3e3c9cf65c70a597097b065dcb24e3";
long dataLogTimer;
#ifdef ESP8266
extern "C" {
#include "user_interface.h"
}
#endif
void logToEmoncms(void)
{
if (millis() < dataLogTimer + UPDATE_PERIOD)
{
return;
}
dataLogTimer = millis();
Serial.print("DATA LOG > ");
Serial.print(dataHost);
Serial.print(" > ");
if (!client.connect(dataHost, 80))
{
Serial.print("Connection failure!");
return;
}
Serial.print("Sending data > ");
String message;
message += "GET http://" + (String) dataHost;
message += "/input/post.json?json={";
message += "EspFastLED_UpTime:" + String (dataLogTimer / 60000) + ",";
message += "EspFastLED_HeapSize:" + String (system_get_free_heap_size());
message += "}&apikey=" + (String) apiKey + "\n";
message += "Connection: close\n\n";
client.print(message);
while (client.available() == 0)
{
if (millis() > dataLogTimer + TIMEOUT_PERIOD)
{
Serial.println("Reply timeout!");
client.stop();
return;
}
}
while (client.available())
{
Serial.write(client.read());
}
Serial.print(" > Done");
client.stop();
// show time to log the data on Emoncms
Serial.print(" in ");
Serial.print(millis()-dataLogTimer);
Serial.println("ms");
}