EmonTX communication with RPi (NTP time)

For some time I have been running my system of an emontx3, 2 current sensors and AC voltage sense communicating via direct serial connect to a RPi 3, but I am having a couple of power fail / restart issues.

  1. Upon restart after a general power failure (happens reasonably often here) the emonhub doesnt seem to be able to recognise the data stream coming from the emontx. Emonhub just reports the “thread is dead” message.
    Things I have tried:
    Restarting the emontx and the Rpi separately. No joy
    monitoring the serial port using a simple python program, or using minicom. Data looks fine

The only thing that works is to edit the emonhub config file and change the serial port number to some illegal value eg TTYAMA1 and then change it back to the correct port TTYAMA0. It all works fine from then on, even if I restart the emontx it continues to read correctly.

  1. Sometimes (eg today) after the power had been out for about 6 hours, upon restart and getting communications working again, I noticed that the emontx wasnt reading one of the current sensors. I checked the data with minicom and it was reporting ‘0’ watts on the main grid feed to the house. The current sensor on the solar feed was working fine, so I restarted the emontx by cycling the power to it and everything worked fine again.

  2. And a general RPi question. After a longer power outage like today, when the RPi restarts the time is so wrong that NTP wont allow resync. I found a way to force it to resync using these commands:
    sudo /etc/init.d/ntp stop
    sudo ntpd -q -g
    sudo /etc/init.d/ntp start
    But is there any way of making it do this automatically.
    I suspect that an additional contributor to the problem is that the internet router takes much longer to start than the RPi, so any solution needs to be able to be delayed by a few minutes after the RPi has restarted.

Hi

If the Pi just has its power removed based on my experience you increase the chance of a SD failure. I now use a UPS that cost about £10 that solves my problem. It is similar to this but mine states V1.2 :-

Of course it will not help if your power outages last longer than the battery life.

Regards

Ian

1 Like

Yes, I have also noticed the issue when the Pi starts up faster than the router. So at bootup, NTP time does not work. I wonder if it would be worth running NTP update at regular intervals. Can anyone see any harm in this? I wonder what a good update rate would be? Once per hr?

It could be a bash script with the NTP stop/start commands that runs once per hr.

If it’s a boot up problem then run a script at start with some sleep seconds or ping the router or or?
If a script is run hourly then the problem could exist for the first hour?

So, No thoughts on why the communications fails after power up?.
I dont know where to even start trying to diagnose the problem. Is there some hook into the emonhub/emoncms app that I can access to see what data it thinks it’s getting?.
Seems odd to me that it will sync up if I force it to refresh the port and will survive a restart of the emontx, so there is no “illegal” characters coming through. Seems more like the emonhub is not initialising properly.

I’ve added a script ~/emonpi/ntp_update.sh:

This script will update NTP time. You can add a line to root crontab run run this script every 1hr to keep time updated:

$ sudo crontab -e

Add the line

0 * * * * /home/pi/emonpi/ntp_update.sh >> /var/log/ntp_update.log 2>&1

This change has been included in the latest emonSD release emonSD-26Oct17.

I’ve added a script ~/emonpi/ntp_update.sh:

This script will update NTP time. You can add a line to root crontab run run this script every 1hr to keep time updated:

$ sudo crontab -e

Add the line

0 * * * * /home/pi/emonpi/ntp_update.sh >> /var/log/ntp_update.log 2>&1

This change has been included in the latest emonSD release emonSD-26Oct17.