• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    C
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ESP8266 WIFI serial to emoncms link

EmonESP

Build Status

ESP8266 WIFI serial to emoncms link

For applications that only require basic posting of data from one emonTx to a remote server such as Emoncms.org an emonTx with this WiFi module provides a lower cost route than an emonBase or emonPi base-station installation.

EmonEsp WiFi AP Setup Portal

Contents

Requirements

  • ESP-12E module with 4M Flash

User Guide

Hardware Setup

First Setup

On first boot, ESP should broadcast a WiFI AP emonESP_XXX. Connect to this AP and the captive portal should forward you to the log-in page. If this does not happen navigate to http://192.168.4.1

Note: You may need to disable mobile data if connecting via a Android 6 device

1. WiFi Connection

  • Select your WiFi network from list of available networks
  • Enter WiFi PSK key then click Connect

Wifi setup

  • emonESP should now connect to local wifi network and return local IP address.
  • Browse to local IP address by clicking the hyperlink (assuming your computer is on the same WiFi network) On future boots EmonESP will automatically connect to this network.

Note: on some networks it's possible to browse to the EmonESP using hostname http://emonesp or on windows http://emonesp.local

If re-connection fails (e.g. network cannot be found) the EmonESP will automatically revert back to WiFi AP mode after a short while to allow a new network to be re-configued if required. Re-connection to existing network will be attempted every 5min.

Holding the boot button at startup (for about 10's) will force AP mode. This is useful when trying to connect the unit to a new WiFi network.

Wifi setup

2. Emoncms

emoncms setup

EmonESP can post data to emoncms.org or any other Emoncms server (e.g. emonPi) using Emoncms API.

In the Emoncms Server field, enter just the hostname or address without any path (e.g. emoncms.org), in the Emoncms Path field enter the path including the leading slash (e.g. /emoncms) or leave it empty if not required.

Data can be posted using HTTP or HTTPS. For HTTPS the Emoncms server must support HTTPS (emoncms.org does, emonPi does not). Due to the limited resources on the ESP the SSL SHA-1 fingerprint for the Emoncms server certificate must be manually entered and regularly updated.

Note: the emoncms.org fingerprint will change every 90 days when the SSL certificate is renewed.

To obtain the certificate fingerprint, you can use several methods, some examples:

  • Chrome under Windows: click the secure icon next to the address bar and click on the certificate row to get the details, in the Details tab copy the hexadecimal digits from the box Thumbprint substituting spaces with colons and paying attention not to include any leading invisible character;
  • Firefox under Linux: click the secure icon next to the address bar, Show connection details, More information, in the security tab click View Certificate and copy the SHA1 Fingerprint
  • openssl under Linux: issue the following command substituting your host in place of www.example.com:

echo | openssl s_client -connect www.example.com:443 -servername www.example.com |& openssl x509 -fingerprint -sha1 -noout

3. MQTT

mqtt setup

EmonESP can post data to an MQTT server. Each data key:pair value will be published to a sub-topic of base topic.E.g data CT1:346 will results in 346 being published to <base-topic>/CT1

  • Enter MQTT server host and base-topic
  • (Optional) Enter server authentication details if required
  • Click connect
  • After a few seconds Connected: No should change to Connected: Yes if connection is successful. Re-connection will be attempted every 10s.

Note: emon/xxxx should be used as the base-topic if posting to emonPi MQTT server if you want the data to appear in emonPi Emoncms. See emonPi MQTT docs.

5. Admin (Authentication)

HTTP Authentication (highly recomended) can be enabled by saving admin config by default username and password

HTTP authentication is required for all HTTP requests including input API

admin setup

7. System

Displays free system memory and firmware version

system

OTA Firmware Update

TBC

HTTP API Examples

View units status:

http://<IP-ADDRESS>/status

Example return in JSON:

{"mode":"STA","networks":[],"rssi":[],"ssid":"OpenEnergyMonitor","srssi":"-58","ipaddress":"10.0.1.93","emoncms_server":"emoncms.org","emoncms_node":"emonesp","emoncms_apikey":"xxxxxxxx","emoncms_connected":"0","packets_sent":"0","packets_success":"0","mqtt_server":"emonpi","mqtt_topic":"emonesp","mqtt_user":"emonpi","mqtt_pass":"xxxxxx","mqtt_connected":"0","free_heap":"25040"}

4. Data Input

Data can be inputed to EmonESP via serial UART or HTTP API.

input setup

UART Input

Data in serial:pairs string format can be inputed to EmonESP via serial UART (115200 baud) e.g:

ct1:3935,ct2:325,t1:12.5,t2:16.9,t3:11.2,t4:34.7

HTTP API

Data in string:pairs can be sent to EmonESP via HTTP API. This is useful to emulate the serial string data function while using the UART for code upload and debug. API example:

http://<IP-ADDRESS>/input?string=ct1:3935,ct2:325,t1:12.5,t2:16.9,t3:11.2,t4:34.7

Save Emoncms server details

http://<IP-ADDRESS>/saveemoncms?&server=emoncms.org&apikey=xxxxxxxxxxxxxxxxxx&node=emonesp&fingerprint=7D:82:15:BE:D7:BC:72:58:87:7D:8E:40:D4:80:BA:1A:9F:8B:8D:DA

SSL SHA-1 fingerprint is optional, HTTPS connection will be enabled if present

Save Emoncms MQTT server details

http://<IP-ADDRESS>/savemqtt?&server=emonpi&topic=emonesp&user=emonpi&pass=emonpimqtt2016

MQTT user and pass are optional, leave blank for connection to un-authenticated MQTT servers


Installation

EmonESP uses ESP8266 core, Arduino framework

Firmware can be compiled and uploaded either using (PlatfomIO,) Arduino IDE, or flashed with pre-compiles binaries found in Releases using esptool.py.

Note different flash sizes of ESP12 module (4Mb) verses Sonoff devices (1Mb).

Option 0: Flash using pre-compiled binaries

Using EmonUpload

Use our emonupload tool to download latest pre-compiled firmware release and upload to EmonESP: https://github.com/openenergymonitor/emonupload

Using Esptool

Find and Install esptool, python required. Navigate to the Releases section of the github page and get the firmware.bin and spiffs.bin files. Use the command below to flash the ESP.

esptool.py write_flash 0x0 ./firmware.bin

If you're having issues uploading try a slower baudrate, --baud 115200 is a failsafe option.

Option 1: Compile Using PlatformIO

For more detailed ESP8266 Arduino core specific PlatfomIO notes see: https://github.com/esp8266/Arduino#using-platformio

1. Install PlatformIO

The easiest way if running Linux is to install use the install script, this installs platformIO via python pip and installs pip if not present. See PlatformIO installation docs.

$ sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

2. Clone this repo

$ git clone https://github.com/openenergymonitor/EmonESP

3. Compile

$ cd EmonESP
$ pio run

The first time platformIO is run the espressif Arduino toolchain and all the required libs will be installed if required.

To compile EmonESP for sonoff s20 smartplugs, WIFI Relay and Heatpump Monitor specify the following environment:

$ pio run -e smartplug
$ pio run -e wifirelay
$ pio run -e hpmon

To compile for 4Mb esp12e modules use environment:

$ pio run -e esp12e

3. Upload

Put ESP into bootloader mode:

  • For Adafruit HUZZAH press and hold GPIO0 button then press Reset, LED should light dimly to indicate bootloader mode.
  • For WiFi relay press and hold the reset button for the duration of the upload
  • For Sonof S20 press the front button when connecting power
  • On Heatpump monitor use jumper to pull GPIO0 low then reset then connect power (simulates reset) or pull RST pin low.
a.) Upload main program:
$ pio run -t upload

To compile and upload EmonESP for sonoff s20 smartplugs, WIFI Relay and Heatpump Monitor specify the following environment:

The default option without specifying any enviroment will upload to the Huzzah

$ pio run -t upload
$ pio run -e smartplug -t upload
$ pio run -e wifirelay -t upload
$ pio run -e hpmon -t upload

4. Debugging ESP subsystems

The ESP subsystems have a lot of logging that can be enabled via setting various build options.

Using Platform IO the easiest way to configure these is via the PLATFORMIO_BUILD_FLAGS environment variable.

First select the serial port to output debug;

-DDEBUG_ESP_PORT=Serial
-DDEBUG_ESP_PORT=Serial1

Then add one or more of the debug options;

-DDEBUG_ESP_CORE
-DDEBUG_ESP_WIFI
-DDEBUG_ESP_HTTP_CLIENT
-DDEBUG_ESP_HTTP_SERVER
-DDEBUG_ESP_HTTP_UPDATE
-DDEBUG_ESP_UPDATER
-DDEBUG_ESP_OTA
-DDEBUG_ESP_SSL
-DDEBUG_TLS_MEM

For example from the Windows Power shell you may do something like;

$env:PLATFORMIO_BUILD_FLAGS="-DDEBUG_ESP_PORT=Serial1 -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI"
pio run -t clean
pio run
pio run -t upload --upload-port 172.16.0.80

Troubleshooting Upload

Erase Flash

If you are experiencing ESP hanging in a reboot loop after upload it may be that the ESP flash has remnants of previous code (which may have the used the ESP memory in a different way). The ESP flash can be fully erased using esptool. With the unit in bootloder mode run:

$ esptool.py erase_flash

sudo maybe be required

Output:

esptool.py v1.2-dev
Connecting...
Running Cesanta flasher stub...
Erasing flash (this may take a while)...
Erase took 8.0 seconds

Development Forum Threads

License

GNU V3 General Public License

More Repositories

1

EmonLib

Electricity monitoring library - install in Arduino IDE's libraries folder then restart the IDE
C++
589
star
2

emonpi

Raspberry Pi Based Energy Monitor. Hardware, Firmware & related software for the PI.
C++
270
star
3

emonTxFirmware

An open-source wireless energy monitoring node
C++
153
star
4

Hardware

OpenEnergyMonitor Open Source Hardware
Eagle
89
star
5

emonhub

Python service linking and decoding input to MQTT & Emoncms
Python
87
star
6

emoncms3

Archived. See https://github.com/emoncms/emoncms for latest version of emoncms.
PHP
78
star
7

STM32

STM32 Energy Monitoring
C++
76
star
8

HeatpumpMonitor

Open-source Heatpump Monitor
C++
74
star
9

learn

OpenEnergyMonitor learning resources (previously building blocks)
HTML
58
star
10

emontx3

EmonTx V3.4.x Hardware and older discreet firmware, see EmonTxV3CM repo for latest
TypeScript
57
star
11

EmonGLCD

Wireless graphical LCD display unit
C++
47
star
12

guide

OpenEnergyMonitor User Guide
HTML
46
star
13

emonTH

An open-source wireless temperature and humidity monitoring node
C++
39
star
14

NanodeRF

emonBase (emonTx >> emoncms) examples using EtherCard library
Arduino
34
star
15

emontx4

emontx4
C++
30
star
16

emonth2

emonTH V2 wireless temperature & humidity sensor with SI7021 sensor
C++
26
star
17

emontx-shield

emonTx Arduino Shield
C++
24
star
18

EmonLibCM

Continuous Monitoring alternative to EmonLib
C++
21
star
19

emontx-3phase

emonTx 'approximate' 3-phase firmware
C++
21
star
20

emontx2

emonTx V2 (through-hole design): A low power, wireless energy monitoring node based on Arduino / JeeNode
C++
20
star
21

NanodeRF_ethershield

Archive emonBase examples - using older EtherShield library
Java
19
star
22

oem_home-assistant

OpenEnergyMonitor emonPi config for Home Assistant
18
star
23

RFM12B_Simple

Simple demo for sending two values (one integer and one float) from one RFM12B to another
Arduino
18
star
24

heatpumpmonitor.org

public list of heat pumps sharing performance data via emoncms
PHP
17
star
25

EmonScripts

Emoncms Stack Installation and Update scripts
Shell
16
star
26

EmonTxV3CM

EmonTxV3 Continuous Monitoring Firmware (Default shipped EmonTxV3 firmware)
13
star
27

emonpi2

RaspberryPi Energy Monitor v2
C++
11
star
28

emonupload

Upload / update latest OpenEnergyMonitor firmware
Python
10
star
29

optical-pulse-sensor

Hardware resources for the optical pulse sensor
10
star
30

mqtt-wifi-mqtt-single-channel-relay

MQTT WiFi ESP8266 Single Channel Relay
10
star
31

ArduinoDue_3phase

Arduino Due (Arm Cortex M3, 12-bit ADC) 3-Phase Example Library
C++
9
star
32

Open-Kontrol-Gateway

Arduino sketches which use the Ciseco OKG as an alternative web-connected emonBase
Arduino
8
star
33

label-generator

Serial number label barcode generator using Glabels
Shell
7
star
34

emonVs

AC Voltage Sensor and Power Supply for emonTx V4 / emonPi V2
7
star
35

LiquidCrystal_I2C1602V1

Arduino Library for HD44780 LCD with PCF8574 I2C controller
C++
7
star
36

RFu_jeelib

Modified version of the JeeLib RFM12B wireless radio driver for use with the Ciseco RFu 328 units V1.x with an RFM12B
Arduino
7
star
37

emonPixel

WiFi LED Pixels
C++
6
star
38

Emon_ecDB

Custom Electronic Component Database Web-App using Emoncms framework
PHP
6
star
39

CommunityEnergyPlanMaker

http://openenergymonitor.blogspot.com/2012/01/community-energy-plan-maker.html
PHP
6
star
40

openevse-solarpv-divert-nodered

NodeRED flow to command an OpenEVSE charging station to control EV charge rate based on available solar PV generation
6
star
41

ElsterMeterReader

ElsterMeterReader
C++
5
star
42

openevse-ac-filter-pcb

240V AC filter for OpenEVSE Controller
4
star
43

cydynni-cordova

Build Android and IOS apps for Cyd Ynni web application
HTML
3
star
44

oem_node-red

Default Node-RED config for emonPi
3
star
45

Ethernet

Official Arduino Ethernet library with required changes to work with with Wiznet W5200 and RFM12B
3
star
46

EmonGLCDlib

Based on JCW glcdlib for ST7565 LCD's, adapted for Vatronix LCD
C
3
star
47

EtherCardOct2012

October 2012 Snapshot of Ethercard library which works with OpenEnergyMonitor MultiNode emoncms posting NanodeRF sketch
C++
3
star
48

emonLibDB

AVR-DB Continuous monitoring library: 3 voltage channels and 12 current/power/energy channels
C++
3
star
49

raspi-dashboard-display

Scripts and config to run a RaspberryPi with HDMI monitor as a public display
Shell
3
star
50

emonpi-ha-bridge

Install guide for ha-bridge (home automation) on emonPi and use Google Home / Amazon Echo to control MQTT devices via voice
2
star
51

blog

OpenEnergyMonitor Blog
HTML
2
star
52

emonEProm

emonEProm
C++
1
star
53

build-workshop

Energy monitor build workshop instructions
C++
1
star
54

homepage

OpenEnergyMonitor front landing page
PHP
1
star
55

heatpumpmonitor-org

https://heatpumpmonitor.org website
PHP
1
star
56

kash_emoncms_flow

Extract P&L data from KashFlow accounting API and post to Emoncms
Ruby
1
star
57

oem_openhab2

OpenEnergyMonitor emonPi MQTT config for OpenHAB2
1
star
58

emonbase

emonBase hardware, firmware and documentation
1
star
59

esphome_components

ESPHome Components
Python
1
star
60

emontx5

EmonTx5, 6 channel energy monitoring transmitter based on emonPi2 measurement board
1
star
61

docs

OpenEnergyMonitor User Guide using Read the Docs
C++
1
star