From emonSD-21Jul21.zip in raspberry Pi code, Watts (power), seen by the clip-on CT sensors, are retrieved for display from…
rootfs/opt/openenergymonitor/emonpi/lcd/emonPiLCD.py r.get(“feed1”) and r.get(“feed2”)
Where in the code are these two values periodically stored on entry to the Pi code from the Arduino (Atmega328) and how often?
“grep feed *.py” in various sub directories does not reveal clues.
Wish-to-know to add a power broadcast capability so any other device that is listening on the same local network can see the values.
As an aside we note
But it just appears to send every 5 mins $broadcast_string = “emonpi.local” if cron is set up as readme.php(?) suggests.
The emonPi software is in two parts, in the “emon” hardware there is an ATMega 328P running almost the same sketch an an emonTx. This sends the data serially, every 5 or 10 s (probably 5) via the GPIO to the Pi, where it is picked up on arrival by emonHub. emonHub then uses an “interfacer” to process the data and send it to wherever it needs to go - usually either to the local emonCMS or to emoncms.org.
Thanks both. MQTT was a good lead. Found
config.get(‘mqtt’, ‘mqtt_feed1_topic’): ‘feed1’, and same for feed2 in emonPiLCD.py
The plan was to intercept the incoming data from ATMega 328P just as it came into the RPI and broadcast it immediately (as soon as it first becomes known to MQTT) so a device on the same local network e.g. terminal on laptop shows the most up-to-date Watts.
Is the power data loaded onto MQTT message queue in the ATMega 328P or RPi?
How does the RPi know when the ATMega 328P has fresh power data for it?
Thanks. I just found “The real power reading is then pushed every 5s to the RaspberryPi for logging and visualisation” in https://guide.openenergymonitor.org/technical/emonpi/
as you suggested.
We are trying to locate the code in the RPi that greets the real power reading that is ‘pushed’ in.
Thanks for replies.
Probably easier to say what we did to get a result and bodies can say if an easier way.
The emonPi is near the electricity meter tethered to CT sensors and not readily accessible. We’d like to see watts in more convenient locations.
So far not found RaspberryPi file (python file?) and line number sought where power data enters* from Atmega328 board. Someplace it gets stored in the Redis database .
However emonPi LCD displays power. In emonPiLCD.py add an import for a UDP transmitter and a function call to this transmitter with the two power reading arguments in the loop.
Near end add 3 lines (3 for clarity but could be 1 line) between existing update and time.sleep
sWatts1 = str(r.get("feed1"))
sWatts2 = str(r.get("feed2"))
netcatRxTx.trnsmt(sWatts1,sWatts2) #From Solar, to House
time.sleep(lcd_update_sec) #30 sec
On one or more devices (e.g. laptop) elsewhere on same LAN we receive power readings. These can be manipulated and displayed.
At present power on laptop gets updated every lcd_update_sec. If one transmitted 6 times per lcd_update_sec loop one could match the sampling rate from the Atmega328. But this could be up to 5s old data as not sychronised to when power data arrives(*). Hence quest to find file & line; it could also be a neater place to transmit from.
Update: The following works in emonPiLCD.py for much more responsive 5s updates
for ix in range(6):
netcatRxTx.trnsmt(str(r.get("feed1")),str(r.get("feed2"))) #From Solar, to Grid (Watts)
time.sleep(5) #30/6 s
#time.sleep(lcd_update_sec) #See emonPiLCD.cfg factory set at 30s