SOLVED - getting the time working on emonGLCD with Pi and RFM12Pi Step by Step

It took me a while of searching about and working this out, I am a newbie to Pi and PHP, hope this helps someone, but I have managed to get the EmonGLCD showing the time from the RFM12Pi

firstly change the code on the emonGLCD....find the void loop () section and change it to this:-

 

 

void loop()
{
 
  if (rf12_recvDone())
  {
    if (rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)  // and no rf errors
    {
      int node_id = (rf12_hdr & 0x1F);
      if (node_id == 11) {emontx = *(PayloadTX*) rf12_data; last_emontx = millis();}
     
      if (node_id == 15)
     
     
      {
digitalWrite(greenLED, HIGH);  // flash the LED to indicate the time is updated
while( rf12_data[0] > 23) // fixes the hour when returned from emoncms,
{  // which returns GMT which results in a negative
rf12_data[0] += 24;  // number from 1800 to midnight in US CTZ
}  // which the rtc can’t understand.

RTC.adjust(DateTime(2013, 2, 25, rf12_data[0], rf12_data[2], rf12_data[3]));
last_emonbase = millis();
delay(25);
digitalWrite(greenLED, LOW);
}

 

 

 

Then you need to alter the raspberrypi_run.php file.....you need to stop it running first (it runs all the time)

on the pi

sudo nano /etc/crontab

find the line with the raspberrypi_run.php file and add a # at the front so

 

* * * * * root cd /var/www/emoncms/Modules/raspberrypi && php raspberrypi_run.php  

becomes

#* * * * * root cd /var/www/emoncms/Modules/raspberrypi && php raspberrypi_run.php

then Do the CTRL-X,Y,[ENTER] thing to save the file.....

 

easiest to reboot then unless you are ok finding and killing the php process....

so...

sudo reboot

 

when it has rebooted it will not be running the raspberrypi_run.php file......

next you need to edit the file:-

 

cd /var/www/emoncms/Modules/raspberrypi

sudo nano raspberrypi_run.php

 

 

look for the line that says:-

 

if (time()-$remotetimer>30 && $sent_to_remote == true)

and just above it add the following text:-

 

if (time()-$todtimer>300)
{
$todtimer = time();

$glcdhour = date('H');
$glcdmin = date('i');

$glcdtime = $glcdhour . ",00," . $glcdmin . ",00,s";
fprintf($f, $glcdtime);
sleep(1);

}

 

 

This will send the time every 300secs and flash the lights on the emonGLCD.....

save this file, then run:-

sudo nano /etc/crontab

and remove the # you added earlier, then reboot again.

sudo reboot

job done hopefully

 

 

 

mattnj's picture

Re: SOLVED - getting the time working on emonGLCD with Pi and RFM12Pi Step by Step

you also need to change the line on the emonGLCD under the template file:-

 

if ((millis()-last_emonbase)>120000)

to

if ((millis()-last_emonbase)>360000)

 

to get rid of the basefail error after 2mins

Jérôme's picture

Re: SOLVED - getting the time working on emonGLCD with Pi and RFM12Pi Step by Step

Hi.

I'm not sure I understand your modifications to raspberry_run.php.

Latest version has that feature included already:

      // Sends the time to any listening nodes, including EmonGLCD's
      if ($settings->sendtimeinterval!=0 &&
          time()-$glcdtime > $settings->sendtimeinterval)
      {
        $glcdtime = time();
        $hour = date('H');
        $min = date('i');
        fprintf($f,"00,$hour,$min,00,s");
        echo "00,$hour,$min,00s\n";
        usleep(100);

And the python script has that as well.

The time interval is a parameter set in the emoncms GUI.

 

mattnj's picture

Re: SOLVED - getting the time working on emonGLCD with Pi and RFM12Pi Step by Step

mmmm, not sure, I only installed my Pi about 2 weeks ago (all downloaded at that time) and the time never worked to the GLCD....

I guess that depends on when the code was updated....but that code you have pasted wasnt in my version... sounds like it has been fixed in the new version already, so you can all ignore what i posted :-)

Comment viewing options

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