EmonGLCD - changing from EmonTX system to Emonpi

Hi,

just found the time to migrate from an EmonTX to a (Kickstarter) EmonPi, and I have a query re EmonGLCD code.  Currently running SolarPV.ino, and it decides whether it's getting an energy packet from the TX or a time update from Emonbase by checking the source node:

if (node_id == 10) {emontx = *(PayloadTX*) rf12_data; last_emontx = millis();}
if (node_id == 15)
{
RTC.adjust(DateTime(2013, 1, 1, rf12_data[1], rf12_data[2], rf12_data[3]));

With the EmonPi, both packets will I believe both have node id = 5.  Before I go hacking the code around, is there an existing preferred fix for this?  I've searched this forum but haven't found anything.

 

I also ran into the bug of Emonhub splitting a node name into multiple lines when there's only one variable sent ( http://openenergymonitor.org/emon/node/11322 ) but found a different workaround, just changed the name to a single letter "T"

Thanks!

pb66's picture

Re: EmonGLCD - changing from EmonTX system to Emonpi

Unfortunately that's not going to work, Previously with the emonTx (node 10) the emonGLCD was listening in on the transmision from the emonTx to the emonBase, when using an emonPi instead of the emonTx, there is no transmission to listen to, plus if it did transmit the data as node 5 as well as the time as node 5 the emonGLCD wouldn't be able to use the node id to distinguish the time from the data.

The emonPi is able to transmit the time and you could extend this to send one packet including both the time and the data, which would also require some minor edits in the emonGLCD sketch. Or you will need to edit emonPi to repeat the locally captured data over the rfm network with a different id. either an edit to the emonPi sketch to just broadcast the data as it passes it to the Pi over serial or in emonhub to TX the dat it gets from the emonpi board or by "fetching" the required data from emoncms in emonhub and TX over rfm.

The last one IMO is the better option, but any will do the job and all will require some coding, with the last one the coding can be all done in emonhub so no sketches to upload.

Paul

Jon's picture

Re: EmonGLCD - changing from EmonTX system to Emonpi

Derek - I have an emonPi and the emonGLCD but I am running a hacked up version of the HomeEnergyMonitor.ino code.  I get my power and time from the emonPi (node 5).  I do not own the emonTX.  I changed the HomeEnergyMonitor.ino code Payload to accept the time and power (and energy).

typedef struct {                //  for data from emonPi for emonGLCD time & "Power Now"
  byte cmd;
  byte hour;
  byte minute;
  byte second;
  byte blank1;
  int32_t WattsNow;
  int32_t kWhAccum;
  byte SendToNode;
} PayloadPi;                    // create JeeLabs RF packet structure
PayloadPi emonPi;

 

And I changed to the EmonHubJeeInterfacer.py code in the "def action(self):" area to send both the time and the power (and energy) to the emonGLCD.

    def action(self):
        """Actions that need to be done on a regular basis. 
        
        This should be called in main loop by instantiater.
        
        """

        t = time.time()

        # Broadcast time to synchronize emonGLCD
        interval = int(self._settings['interval'])
        if interval:  # A value of 0 means don't do anything
            if (t - self._interval_timestamp) > (interval):
                self._interval_timestamp = t
                now = datetime.datetime.now()
                self._log.debug(self.name + " Broadcasting time: %02d:%02d:%02d" % (now.hour, now.minute, now.second))
                sendstr = "00,%02d,%02d,%02d,00" % (now.hour, now.minute, now.second) 

        # Add Power at end of Time string
                packet = urllib2.urlopen("http://localhost/emoncms/feed/fetch.json?ids=1,2&apikey=emonPi_emoncms_read_apikey").read()
                packet = packet.translate(None, '"[]')                    #  packet is a string <type 'str'>  -  1101,1138.1513306719
                
                packet = packet.split(',')                                #  packet is a list <type 'list'>  -  1101,1138.1513306719
 

                for value in packet:
                    value = int(round((float(value) * 10)))
                    myPackData = struct.pack('<i', value)
                    bytes = struct.unpack('<BBBB', myPackData) 
                    for byte in bytes:
                        sendstr = sendstr + (",%d" % int(byte))

                sendstr = sendstr + ",00,s"
                #self._log.debug(self.name + " sendstr " + sendstr)
                self._ser.write(sendstr)

The above was with the help of many others on this forum!  How to send feed data from emoncms to emonGLCD?

Hope this helps - Jon

Derekb's picture

Re: EmonGLCD - changing from EmonTX system to Emonpi

Thanks for the quick response guys,

I'll probably put the time in the main payload - looks as if I'm doing some recoding!

In the meantime I plan to leave the old emonbase powered up on node 15 just to provide a temporary time signal...

regards

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.