Sending data to emonCMS server

A project log for ESP Swiss Knife

This battery powered device is a all-in-one toolbox : WiFi AP, 3D printer remote, clock, serial console, sensors hub, and many more...

arcadia-labsArcadia Labs 05/25/2016 at 19:570 Comments

The device sends its voltage and temperature to my emoncms server.

Emoncms ( is an open-source web-based software for monitoring home power, temperature and sensors. This is a central part of my DIY home automation system.

Emoncms exposes an API, so reading / posting data to the server is very easy.

Here is the piece of code I'm using :

#define emoncms_host ""
const int emoncms_httpPort = 80;
String emoncms_apikey = "YOUR_API_KEY";
int node = 1;

void postEmoncms() {
  // run only if the ESP is connected to a network
  if ( WiFi.status() == WL_CONNECTED ) {
    WiFiClient client;
    if (!client.connect(emoncms_host, emoncms_httpPort)) {
      Serial.println("Post to emoncms failed");
    // We now create a URI for the request
    String url = "GET /emoncms/input/post.json?apikey=" + emoncms_apikey + "&node=" + node + "&json={2:" + temperature + ",1:" + vcc + "";
    client.print("Host: ");
    client.println("Connection: close");
    client.stop(); //Stopping client
    Serial.println("Post to emoncms : success");
  else {
    Serial.println("Post to emoncms : not connected to internet");
Of course, this function shouldn't run constantly in the main loop, but should run on timed intervals. I'm using RBD_Timer lib (

This function runs in the background, so there won't be any screenshot this time !