Skip to content

Commit

Permalink
Included logging to Emoncms.org
Browse files Browse the repository at this point in the history
  • Loading branch information
krzychb committed May 31, 2016
1 parent 29e4002 commit 82ae2e0
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 26 deletions.
8 changes: 8 additions & 0 deletions EspAdafruit_NeoPixel/Emoncms.h
@@ -0,0 +1,8 @@
#ifndef _EMONCMS_H_
#define _EMONCMS_H_

#include <WiFiClient.h>

void logToEmoncms(void);

#endif //_EMONCMS_H_
68 changes: 68 additions & 0 deletions EspAdafruit_NeoPixel/Emoncms.ino
@@ -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");
}

18 changes: 10 additions & 8 deletions EspAdafruit_NeoPixel/EspAdafruit_NeoPixel.ino
@@ -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();
}
8 changes: 8 additions & 0 deletions EspFastLED/Emoncms.h
@@ -0,0 +1,8 @@
#ifndef _EMONCMS_H_
#define _EMONCMS_H_

#include <WiFiClient.h>

void logToEmoncms(void);

#endif //_EMONCMS_H_
68 changes: 68 additions & 0 deletions EspFastLED/Emoncms.ino
@@ -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");
}

18 changes: 10 additions & 8 deletions EspFastLED/EspFastLED.ino
@@ -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();
}
8 changes: 8 additions & 0 deletions EspNeoPixelBus/Emoncms.h
@@ -0,0 +1,8 @@
#ifndef _EMONCMS_H_
#define _EMONCMS_H_

#include <WiFiClient.h>

void logToEmoncms(void);

#endif //_EMONCMS_H_
68 changes: 68 additions & 0 deletions EspNeoPixelBus/Emoncms.ino
@@ -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");
}

18 changes: 10 additions & 8 deletions EspNeoPixelBus/EspNeoPixelBus.ino
@@ -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();
}
7 changes: 5 additions & 2 deletions readme.md
Expand Up @@ -72,7 +72,7 @@ To do the testing I have collected the following hardware:
- **ESP8266 module** - NodeMCU 1.0 (ESP-12E Module). I have selected this one to make my prototyping more convenient. It has USB / serial interface and power supply on board, so you do not need to provide them separately. You can use any other [typical ESP8266 modules](https://github.com/esp8266/Arduino/blob/master/doc/boards.md#table-of-contents) as well. One single pin GPIO3 (TXD0) is used for driving WS2812B and make sure it is broken out in your module.
- **Pixel strip power supply** - Adjustable DC-DC power supply CN4015-3.1 together with AC-DC 12V power supply. You should be able to go away with a "wall wart" 5V DC power supply assuming it will match power consumption of your LED strip. To avoid potential issues with 3.3V logic of ESP8266, use an adjustable power supply and lover output voltage below 5V. For more details please check excellent guide ["Powering NeoPixels"](https://learn.adafruit.com/adafruit-neopixel-uberguide/power) by Adafruit.
- **1000uF/16V capacitor** to improve quality of power supply to the pixel strip - see ["Best Practices"](https://learn.adafruit.com/adafruit-neopixel-uberguide/basic-connections) by Adafruit.
- **470Ω resistor** to separate ESP8266 and the pixel strip. For more details please check ["Best Practices"](https://learn.adafruit.com/adafruit-neopixel-uberguide/basic-connections) by Adafruit.
- **470? resistor** to separate ESP8266 and the pixel strip. For more details please check ["Best Practices"](https://learn.adafruit.com/adafruit-neopixel-uberguide/basic-connections) by Adafruit.
- **Bread board and cables** - see also ["Basic Connections"](https://learn.adafruit.com/adafruit-neopixel-uberguide/basic-connections) by Adafruit.

![Connection of NeoPixels to ESP8266 - schematic](pictures/EspNeoPixelConnection.png)
Expand Down Expand Up @@ -107,7 +107,9 @@ Application prepared for ESP8266 consists of the following files:

1. [Fire.ino](EspFastLED/Fire.ino) together with [Fire.h](EspFastLED/Fire.h) - fire simulation code that primarily contains original Fire2012 application.
2. [WebInterface.ino](EspFastLED/WebInterface.ino) together with [WebInterface.h](EspFastLED/WebInterface.h) - web interface shown on the [picture above](#fire2012) and Wi-Fi set up routines.
3. [EspFastLED.ino](EspFastLED/EspFastLED.ino) - a simple main sketch that integrates the above *Fire* and *WebInterface*.
3. [Emoncms.ino](EspFastLED/Emoncms.ino) together with [Emoncms.h](EspFastLED/Emoncms.h) - routines to post data on [Emoncms.org](Emoncms.org) to monitor application up time, heap size and other parametrs if required. You need to set up an account on Emoncms.org to use it. This is quick and simple - please refer to my [OnlineHumidifier](https://github.com/krzychb/OnlineHumidifier/tree/master/6-Chart#emoncms) repository that explains how to do it.
4. [EspFastLED.ino](EspFastLED/EspFastLED.ino) - a simple main sketch that integrates the above *Fire*, *WebInterface* and *Emoncms*.


EspFire2012 application has been tested with three previously described libraries for NeoPixel control. Respective application versions are available for your review in the following folders:

Expand All @@ -129,6 +131,7 @@ In ``` loop() ``` the following two functions are repeatedly called:

```
server.handleClient(); // respond to commands from web browser
logToEmoncms(); // Log aplication performance data to Emoncms.org
keepFireAlive(); // simulate Fire2012
```
The main sketch file names have been changed to distinguish tested libraries.
Expand Down

0 comments on commit 82ae2e0

Please sign in to comment.