difficulties with packetgen module

Hi everybody,

I played a bit around with the really cool packetgen module while trying to send unixtime (seconds) in the same way like hour, minute and second is done. My code piece in packetgen_model.php is (at two places)

...

// special variable values
      if ($variable->name=='hour') $variable->value = date('H');
      if ($variable->name=='minute') $variable->value = date('i');
      if ($variable->name=='second') $variable->value = date('s');
          
// (arwed) added ...
        //$unixSeconds = time();
        if ($variable->name=='unixtimeL') $variable->value = (date('U')) & 0x0000FFFF;
        if ($variable->name=='unixtimeH') $variable->value = (date('U') >> 16) & 0x0000FFFF;

...

That works a bit so far, but ist sends _static_ values for unixtime (the value from when I opened the page) -- while the hour minute and second values are updating. I obviously missed something --- but don't know what. Could anybody, please, give me a hint?

Would be great. Thanks a lot in advance

arwed

mdbigg's picture

Re: difficulties with packetgen module

From what I can tell Packetgen stores the contents of the packet in a database at the time of creation/editing. Thus the values would be static.

Have you added your code into the getrfm12packet function? I think you'll need to set the values to the current time at that point.

arwed's picture

Re: difficulties with packetgen module

Hi mdbigg,

I added the code twice because I found the three lines with hour / minute / seconds in two places: in the function "get($userid)" _and_ in "function getrfm12packet($userid)".

But at least hour minute and second ar enot static data, because they are continuously updating. I've defined in packetgen to get 'hour', 'minute', 'second' (all as bytes), 'unixtimeL' and 'unixtimeH' (as int). What I receive in my sketch is

> Received 7 bytes from Node #16 ... : 21 51 3 221 91 208 82

and a little later

> Received 7 bytes from Node #16 ... : 21 53 5 221 91 208 82

So the first three _do_ update, the last four, my wanted values, do _not_. They only get new correct values when I refresh the packetgen webpage.

Ther must be something that I missed. But I could not find anything magic with the hour / minute /second values so far.

 

mdbigg's picture

Re: difficulties with packetgen module

Can you post the whole of your updated packetgen_model.php for us to have a look at please?

arwed's picture

Re: difficulties with packetgen module

yes, of course. I attached it; I hope that works.

On the Packetgen webpage i defined the following:

Current packet size: 7/66 bytes

Property name Type Value
---------------------------------------

hour          byte 10
minute        byte 48
second        byte 16
unixtimeL     int 4960
unixtimeH     int 21201

and -- as shown -- with each page refresh both, the hour / miunte /second and the unitime values are updating correctly.

 

Just two little other questions: Is there an easy way to log to rfm12piphp.log what was sent? I only see there

LENGTH: -> 7 b

which seems to come from my 7 bytes message.

And how could I just stop sending packages from the packetgen module (probably like on the RaspberryPi page with interval set to 0)?

Thanks a lot for your help in advance!

 

mdbigg's picture

Re: difficulties with packetgen module

I can't see why it wouldn't work.

Look up the packetgen section in raspberrypi_run.php. You should be able to add an echo to print out whatever the packet being broadcast is. You could also modify the if clause so it doesn't broadcast if $controlinterval==0. (I guess you'll also need to edit the packetgen view to give the option of setting the control interval to 0).

 

Is packetgen converting the unixtime to two separate bytes properly?

arwed's picture

Re: difficulties with packetgen module

OK, I added an echo line as you suggested. I alredy tried this a while ago, but it did not work. Now I know: I had to restart the script after changing. ;-( Could I have tried already ...

Now I see this in the log:

Now sending: 17,49,26,22,118,209,82,

which is hour,minute,second and the four byte values of the unixtime. And -- surprisingly: the values _are_ changing now! Even the received values! That's weird -- but really good. Obviously your thoughts helped my script ... I don't know.

But anyway, many thanks for your hints; I've learned new stuff. Now I'll try to set the controlinterval to 0.

Thanky you, mdbigg, and thanks to all the supporters on EmonCMS!

arwed

mdbigg's picture

Re: difficulties with packetgen module

I'm guessing that re-starting the script resolved the problem. Unless this happens all your changes won't take effect!

Comment viewing options

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