Modification to RFM12Pi software

I have just received and built a RFM12Pi and managed to connect it to emoncms etc, all appears to be working well.

I currently have an EmonTX, EmonBase and EmonGLCD.

I am now thinking to stopping using the Emonbase as the updating of emoncms can be done via the Raspberry Pi + RFM12Pi setup, however currently the Emonbase unit I have sends out the current time which the EmonGLCD displays which is something I want to keep if possible.

What changes do I have to make to the RFM12Pi software to allow the RFM12Pi to send the date/time out instead, unfortunately my C++ knowledge is very limited.

mharizanov's picture

Re: Modification to RFM12Pi software

Th RFM2Pi board can send data packets, I have experimented with this in my early designs (in perl)

Something like this (>>>UNTESTED<<<<) in PHP should work:

$hour = date('H');

$min = date('i');

fprintf($f,$hour.",00".$min.",00,s");  

sleep(1);

inserted right after posting the data to emoncms

https://github.com/emoncms/raspberrypi/blob/master/raspberrypi_run.php#L100

 

[fprintf statement edited to fix a typo where I had comma instead of dot]

gb095666's picture

Re: Modification to RFM12Pi software

Thanks for your reply.

I have updated the perl script but cant seem to see any data coming from the RFM2Pi board.

Are there any error logs I can check to see if the perl script is working ? or any way of checking to see what the RFM2Pi module is transmitting ?

 

mharizanov's picture

Re: Modification to RFM12Pi software

EmonGLCD expects the time packet from certain NodeID. Make sure that NodeID is the same as the RFM2Pi's - you can either modify emonGLCD's code or easier - configure the RFM2Pi board to use that NodeID

To test the sending , you can load the RF12demo sketch on another node and watch the serial output

https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo

Also, you can manually send test packet from minicom by typing:

17,00,30,00,s

that should post a message telling emonGLCD that it is 17:30 now

gb095666's picture

Re: Modification to RFM12Pi software

Thanks, I am getting closer.

If I go into minicom and enter the time manually is works, the GLCD display changes, so I know the nodeid etc is correct.

However it doesn't pick it up from the PHP script.

 

 

ukmoose's picture

Re: Modification to RFM12Pi software

Try 

fprintf($f,$hour.",00,".$min.",00,s");
gb095666's picture

Re: Modification to RFM12Pi software

Still doesn't work unfortunately, the frustrating thing is I have echo'ed the line out and it all looks ok, it's as if it's not being transmitted ?

ukmoose's picture

Re: Modification to RFM12Pi software

Have you rebooted since using minicom?  The first process that grabs the serial port doesn't play well with anything else that tries to use it.

 

gb095666's picture

Re: Modification to RFM12Pi software

Yes, I have rebooted a few times, but thanks for the information as I didn't know that.

gb095666's picture

Re: Modification to RFM12Pi software

I have updated the raspberrypi_run.php script with the following lines

            $url = "/emoncms/input/post?apikey=".$apikey."&node=".$values[1]."&csv=".$msubs;
            getcontent("localhost",80,$url);

            $hour = date('H');
            $min = date('i');
            fprintf($f,$hour.',00,',$min.',00,s');
            echo $f,$hour.',00,',$min.',00,s';

The output from the PHP is

SERIAL RX: 10 3 0 122 5 44 13 113 3
3,1402,3372,881
Resource id #1022,00,28,00,sSERIAL RX: 10 2 0 117 5 44 13 113 3
2,1397,3372,881
Resource id #1022,00,29,00,sSERIAL RX: 10 1 0 126 5 44 13 113 3
1,1406,3372,881
Resource id #1022,00,29,00,sSERIAL RX: 10 0 0 120 5 44 13 113 3

The local time was 22:28 to a minute later which you can see above, but the thing that confuses me is the Resource id which looks to be 10.

I need the time sending out as though it's come from node 15, should that say resource id #15 ? and if so how do I change it ?

 

TrystanLea's picture

Re: Modification to RFM12Pi software

$f is the file handler, so resource id #10 is something to do with that rather than the node id, 

echo '$values[1],$hour.',00,',$min.',00,s'; should give the node id. EDIT, or am I missing something and your using $f for the node id?

gb095666's picture

Re: Modification to RFM12Pi software

Hi Trystan,

Thanks for the info, still doesn't look right though, still says "10" from the following code.

            $hour = date('H');
            $min = date('i');
            fprintf($f,$hour.',00,',$min.',00,s');
            echo $values[1],$hour.',00,',$min.',00,s';

SERIAL RX: 10 4 0 245 2 44 13 132 3
4,757,3372,900
1023,00,44,00,s

SERIAL RX: 10 4 0 243 2 44 13 132 3
4,755,3372,900

EDIT, All I am trying to do is get the RaspberryPi to send out the current time so that the GLCD can pick it out, The GLCD is expecting the transmission to come from a nodeid of 15.

Currently I have an emonTX as node 10, a raspberrypi as 15 and a GLCD of 20.
 

gb095666's picture

Re: Modification to RFM12Pi software

Managed to fix it.

           $hour = date('H');
           $min = date('i');
           fprintf($f,$hour.",00,".$min.",00,s");
           sleep(1);

 

Inserted after line 100

https://github.com/emoncms/raspberrypi/blob/master/raspberrypi_run.php#L100

 

Is there any chance it can be incorporated into the standard version ?

fluppie007's picture

Re: Modification to RFM12Pi software

Indeed, I think this is interesting to have by default :-) !! I would like to have a 'correct' clock on the emonGLCD.

EDIT:

Tried to insert your code after line 100, it freezes my inputs/feeds. Inserting it before line 100 works, but funny enough only the minutes on my emonGLCD are updated. The hour remains 0. Insertion after line 100 doesn't work at all, also the inputs/feeds get frozen.

I also set my time zone to Europe/Brussels in the PHP ini file. Used the following command sudo nano /etc/php5/apache2/php.ini

I attached a screencap from the modifications in raspberrypi_run.php

mharizanov's picture

Re: Modification to RFM12Pi software

There have been quite a few revisions thereafter, it is no longer on line 100.

 

look up this code and insert that snippet after it:

 

             //echo $msubs."\n";
            $url = "/emoncms/input/post?apikey=".$apikey."&node=".$values[1]."&csv=".$msubs;
            getcontent("localhost",80,$url);

 

fluppie007's picture

Re: Modification to RFM12Pi software

fluppie007's picture

Re: Modification to RFM12Pi software

In my case, it works for only the minutes. Hours won't get updated, they stay 0 at all hours.

What also is weird is that the emonCMS server freezes/locks up after +- 2 hours. Rebooting the Pi solves the problem. I removed the "time updater" from the PHP file and now my Pi logs without any problem. So I guess this still isn't a 100% working solution?

gb095666's picture

Re: Modification to RFM12Pi software

I think I am close to solving this, just one more bug to get through and then I will have all the piece's I think.

The only problem I have now is after roughly 20 mins the RaspberryPi seems to start transmitting under a different BaseID

I have a spare NanodeRF which I have basically set it up to monitor what transmission come from which node, when I boot the RaspberryPi it starts sending time information from a BaseID of 15 which is correct, but after 20 mins it changes to transmitting from BaseID 14 ?

I have checked the SQL database and it's OK in there.

Any idea's why the baseID is changing ?

fluppie007's picture

Re: Modification to RFM12Pi software

Don't have a clue but could it help (just for debugging) to set your RFM2Pi board to node ID 14? Cool that you're looking after it :-)!!

TheBluProject's picture

Re: Modification to RFM12Pi software

Same here, I'm afraid, It updates my minutes, but the hour is 0 ... Haven't tested long enough to tell if it locks out my feeds / inputs. I'm using the ready-made rasbian with emoncms built by tristan, maybe there are some variable name differences or something ? 

When I'm trying to do the manual minicom  time instertion it throws some random chars @ me, even with the crontab entry commented out and process killed. When I'm inserting the RasPI shield it should spit out the command list, but it gives u partial content mixed with random characters. Reception from both EmonTX and EmonGLCD is fine, tho .. Any ideas ??

ukmoose's picture

Re: Modification to RFM12Pi software

The code to send the time to emonglcd has moved on since this topic was active ( a week ago!)

In order to get the RFM12PI board transmitting time data to your emonGLCD and requires a firmware update to the 

software running on the RFM12PI board.

Please look at and follow the instructions at:

http://openenergymonitor.org/emon/node/1506

 

 

Comment viewing options

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