Skip to main content



A Raspberry Pi  running EmonCms collects my sensor data and controls devices around the home and this was the primary reason for designing the mmPi to manage the shutdown and power supplies including UPS support when available.

EmonCMS is a very simple but powerful open source application intended originally for home power monitoring but with the addition of another open source application, Node-Red, it can be turned into an extremely flexible Logger or Home automation system. With addition of the mmPi project the possibility of writing user programs in MMBasic , making use of all the facilities of the Raspberry Pi and EmonCMS via the interfacing power of Node-Red. Communication between the RPI and mmPi is via a simple Json serial signaling protocol.

The following documentation describes how to setup a Raspberry Pi to run EmonCMS and Node-Red.

This section covers the steps that are required to get EmonCMS and Node-Red installed on a Rasperry Pi.
The simplest method is to download the mmPi-EmonCMS.Img file to your computer and then flash the image to a SD card.
Alternatively you can build a system using an EmonCMS image and then the extra application and setup added afterwards .
Build a System
  • Download the latest EmonCMS image here .
  •  (2) Write to a 16Gb SD card. Etcher is recommended see here .
  • Make SSH available without a screen (Headless) by editing the new SDcard here.
  • Place the new SDcard into the Raspberry Pi and apply the power.
  • (5) Please read the EmonCMS Connection Guide .
  • (6) Follow the connection guide to connect your Raspberry Pi to your Network & setup EmonCMS.
  • Now login to your Raspberry Pi via SSH to load software and make System setup. If you have not done this before see here. Login to the Pi as User: Pi and Password: emonpi2016 .
  • Install Node-Red by following the guide here .
  • Use Raspi-config utility to enable the serial port (No Console) and set your correct location. See here .
  • Setting up the Raspberry Pi

    It is assumed that the Raspberry Pi is already setup and working correctly either in Desktop or Headless configuration. In order for the RPI to work correctly with the mmPi pcb a couple lines must be added to the /boot/config.txt file on the Raspberry Pi SD card.

    Open /boot/config.txt in nano (or your preferred editor):

    sudo nano /boot/config.txt
    Copy or re-type the below into the file. The “#” line is just a comment .
    #This sets up the ability for a pushbutton switch to shut it down:
    #Also the Raspberry Pi's status is signaled via Gpio Pin4 

    Save and exit the file with control-X, Y <return>.

  • Optional. Install PiLedLights to control some Leds to show Network and SD/HDD activity, see here.
  • Optional. Install RPI-Clone for System Clone. See here .
Use the mmPi-EmonCMS.img file (recommended)
  • Download the img file below .
  • Write the image to an SD card as in step 2 above.
  • Follow steps 5 & 6 to setup your network and EmonCMS.

Node-Red , system setup and other optional software has already been setup in the image.

 Use the mmPi-Pico page as a guide for setting up your hardware.

Setup and Using EmonCMS etc.

mmPi uses the Serial 0 com port of the Raspberry Pi but EmonCMS also in its standard setup may also want to use this port. EmonHub is the application that uses the com port but EmonHub is not being used in out setup so we can disable the application in the EmonCMS setup information page.

Stop the application first and then press Disable.

There is the possibility in certain circumstances (like during an update) that it may get restarted so for a more permanent solution, it is probably better to remove the  Serial Port references in the Interfacers section of the EmonHub Configuration and leave EmonHub running.

Delete the Highlighted lines and Save the file again.



Node-Red was designed for "stitching" applications together. In this application it can be used to route I/O Sensor data to/from the mmPi (rpi Pico) and the Network (HTTP,UDP,TCP) also EmonCMS. One of the hardware possibilities of the RPI-Pico and MMBasic is to provide some ADC inputs which the Raspberry Pi 3/4 does not have. Node-Red can also provide extensive Network/Internet access.

Rpi-Process.json is the flow used in Node-Red that gets the Raspberry Pi CPU temperature (Date & Time) and sends it to the mmPi. It is then used by the mmPi to control the Fan Speed. Here is the Node-Red visual representation, the actual flow in json is in the Files section.










The purpose of this document was not to describe a complete working project but just to touch on some possibilities and examples.

Here is an actual working example:

My House power supply consists of a Grid Connection and  3kw Roof Top Solar. The Solar is controlled by a Fronius 3kw invertor and data requested via HTTP GET request (via wifi). The House Utility energy LED is monitored by a pulse sensor and the data is sent via a ESP8266 using UDP (EspEasy). A better way to measure house grid current would be via a CT sensor but cables are not readily accessible and would require a qualified electrician visit to install, so is not available. So for this reason we need to estimate the house current and Grid Input/Output whilst Solar generation is providing all power usage. This calculation is all performed in the mmPi before sending results to EmonCMS storage and display. So to recap the Grid data is sent via UDP, the Solar data is requested via HTTP GET, the data is all processed by Node-Red and sent as Json strings to mmPi. MMBasic processes the data , averages and calculates all the new fields of data ,power (usage), Solar, Gridin, Gridout, Gridavg .

mmPi code to process Grid and Solar data

  'process json strings from RPI
Sub userprocess
  print "Process:";newline$
  getjson newline$,pw$,"count"
  getjson newline$,sw$,"solar"
  getjson newline$,ot$,"otemp"
  getjson newline$,oh$,"ohum"
  getjson newline$,ws$,"speed"
  getjson newline$,wg$,"gust"
  getjson newline$,wd$,"dir"
  getjson newline$,ra$,"rain"
  getjson newline$,pr$,"pres"
  'print pw$;" ";sw$;" ";ot$;" ";oh$;" ";ws$;" ";wg$;" ";wd$;" ";pr$;" ";ra$
end sub
  'calculates solar/usage and sends to Pi
sub gridpower
  local nogridpower,ginpower,goutpower,rndom
  'check solar contribution
  if nogridpower>0 then
    upower=int(upower)+spower  'add solar to grid power
    'find grid in average
  else                    'solar is greater than grid input
    ' print "Calc Power.."
    'so apply just an average grid usage and the balance as grid out
    rndom=(Rnd * 100) + gridavg
    'print "Random:"; random
    smooth rndom
    'print "smooth:";  upower
    checkpos ginpower
    checkpos goutpower
  end if
  print "latest watts:";upower
  print "latest Solar:";spower
  print "to Grid:";goutpower
  print "from Grid:";ginpower
  print #5,power$
end sub

print #5,power$ sends a json string back to Node-Red , {"power":645,"solar":1879,"gridout":1234,"gridin":0,"gridavg":480}

Node-Red receives the json string and the "Power Usage" node strips out the json string and sends it to EmonCMS via the "Power Gen/Usage" node.


The json string is processed by Emoncms.

stored in the data base and visualised by the Graph module.














  • mmPi EmonCMS image (Recomended)

mmPi-EmonCMS.img (Zip)

node-red  Rpi-Process flow (json)


Leave Comment