Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
263 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _EMONCMS_H_ | ||
#define _EMONCMS_H_ | ||
|
||
#include <WiFiClient.h> | ||
|
||
void logToEmoncms(void); | ||
|
||
#endif //_EMONCMS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#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 += "EspAdafruit_NeoPixel_UpTime:" + String (dataLogTimer / 60000) + ","; | ||
message += "EspAdafruit_NeoPixel_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"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
#include "WebInterface.h" | ||
#include "Fire.h" | ||
#include "Emoncms.h" | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_Adafruit"); | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_Adafruit"); | ||
|
||
setupWiFi(); | ||
setupWebServer(); | ||
setupWiFi(); | ||
setupWebServer(); | ||
|
||
setupFire(); | ||
setupFire(); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
server.handleClient(); | ||
keepFireAlive(); | ||
server.handleClient(); | ||
logToEmoncms(); | ||
keepFireAlive(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _EMONCMS_H_ | ||
#define _EMONCMS_H_ | ||
|
||
#include <WiFiClient.h> | ||
|
||
void logToEmoncms(void); | ||
|
||
#endif //_EMONCMS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "Emoncms.h" | ||
|
||
WiFiClient client; | ||
|
||
#define UPDATE_PERIOD 60000 | ||
#define TIMEOUT_PERIOD 1000 | ||
const char* dataHost = "emoncms.org"; | ||
const char* apiKey = "be71f01adf17bfa1a85118923c0140b4"; | ||
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"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
#include "WebInterface.h" | ||
#include "Fire.h" | ||
#include "Emoncms.h" | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_FastLED"); | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_FastLED"); | ||
|
||
setupWiFi(); | ||
setupWebServer(); | ||
setupWiFi(); | ||
setupWebServer(); | ||
|
||
setupFire(); | ||
setupFire(); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
server.handleClient(); | ||
keepFireAlive(); | ||
server.handleClient(); | ||
logToEmoncms(); | ||
keepFireAlive(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef _EMONCMS_H_ | ||
#define _EMONCMS_H_ | ||
|
||
#include <WiFiClient.h> | ||
|
||
void logToEmoncms(void); | ||
|
||
#endif //_EMONCMS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "Emoncms.h" | ||
|
||
WiFiClient client; | ||
|
||
#define UPDATE_PERIOD 60000 | ||
#define TIMEOUT_PERIOD 1000 | ||
const char* dataHost = "emoncms.org"; | ||
const char* apiKey = "be71f01adf17bfa1a85118923c0140b4"; | ||
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 += "EspNeoPixelBus_UpTime:" + String (dataLogTimer / 60000) + ","; | ||
message += "EspNeoPixelBus_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"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
#include "WebInterface.h" | ||
#include "Fire.h" | ||
#include "Emoncms.h" | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_NeoPixelBus"); | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println("Fire2012_NeoPixelBus"); | ||
|
||
setupWiFi(); | ||
setupWebServer(); | ||
setupWiFi(); | ||
setupWebServer(); | ||
|
||
setupFire(); | ||
setupFire(); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
server.handleClient(); | ||
keepFireAlive(); | ||
server.handleClient(); | ||
logToEmoncms(); | ||
keepFireAlive(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters