Hi.
I've been reading about this subject, and I'm not sure of the best way to do it.
To transmit variables to the EmonPi firmware,is it necessary to use packetgen or the EmonPi's internal EmonCMS can do that by itself?
I've seen that there is Tx information after the Rx variables in Nodes section
Tx ID Name Last updated Value
I suspect I would be able to configure them with something like this in the emonhub config section:
[[[tx]]]
names = var1, var2
datacodes = h, h
scales = 1, 1
units = %, delay
But, if this would even work what would be the method to receive the variables in the EmonPi firmware?
Cheers.
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
This is turning to be not as easy as it seems... And the proof is that, after two days, no one gave any hint.
I've tried the RFM12b Packet Generator and I cant see any information about it's packets on the emonhub log, it seems that it is not working...
With the other option, configuring the [[[tx]]] in the emonhub.conf I get the packets logged in emonhub.log, but I'm not being able to receive anything in the arduino.
Don't know what else to try, any ideas?
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
All packetgen does is set up a packet that can be retrieved via the packetgen api, there was a hack for the original emonhub to poll packetgen and pass the packet out via the rfm2pi but that pre-dates the [[[tx]]] sections in emonhub.conf and was a hardcoded hack. The experimental branch from which the "emon-pi" variant originated also had a packetgen interfacer which didn't get carried over.
The "fetch" feed api was added to emoncms for the purpose of using any feed value in emonhub via http, but the emon-pi variant has been focused on mqtt so you will probally need to look at the "publish to mqtt" process in emoncms and the mqtt interfacer in emonhub.
I know G&T have succesfully switched on and off a desk lamp via emoncms -> emonhub -> rfm2pi but I cannot find any ref to that now.
each interfacer in emonhub uses an internal pub/sub bus to pass data and anything published to "ToRFM12" should get transmited
Paul
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Hi.
I think that now my problem is about receiving the packet inside the firmware, look at this:
This was accomplished with the [[[tx]]] form I referred earlier.
Do you think that even with this lines appearing on the emonhub log the packets could not be passing through?
There seems to be a bug anyway, but it is not important now, if my [[[tx]]] variable has more than one char, one line for each char appears in the nodes section.
Cheers.
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
There seems to be several formatting errors there. The frame "5,199,0,s" is correct to "broadcast" 3 values of 5, 199 and 0. the value immediately before the trailing command letter (but not separated by a comma) is the node id, in this case it is omitted and therefore 0 which in JeeLib means broadcast using the transceivers own node id as a "from id" (the default base id is usually 15).
So all or any of your nodes should be able to receive the packet IF they are listening for node 15 or 31, node 31 is promiscuous mode and accepts any node id, like the rfm2pi firmwares do.
This is also assuming the frame is accurately logged and "5,199,0,s" is exactly what is passed to the rfm2pi. This part definitely worked as intended in the "experimental" branch's JeeInterfacer but I wasn't involved in the "emon-pi" variant so I'm not that familiar with it
Paul
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Hi.
About this transmission packet, it seemed ok to me because I did understood what was being transmitted, but it doesn't mean it is correct (as you said):
5 -> node ID (at least is the node ID of EmonPI)
199 -> the low significant part of the integer being sent 199;
0 -> the high significant part of the integer being sent 199;
s -> this I thought was some control to signal the end of the packet.
I don't completely understand how this works, because there is no RF involved, the packet is transmited just through the serial connection into emonPi.
You say something about the listening node (15 or 31), but (while testing) as I comment the line that verifies the node if (node_id == 5), it should receive any node, shouldn't it?
Cheers.
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Without looking closer I'm not sure about commenting out the "if" line the way you have, will the braced code still run without it? you could try removing the braces too or replacing the if with an absolute result eg if 1 == 1;
The JeeLib use of byte values to construct integers and long etc is necessary due to the "rf packet" format, if just communicating over serial with the emonpi you could indeed just use ascii strings for values rather than lsb and msb etc.
I will try and free up some time to look at this later if I can. I do not know exactly how things are implemented in emon-pi or emonPi.
Paul
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Hi.
I will later try what you say about the braces, but I don't see any reason for the code to be passed without being executed, at least it never happened to me in any language I used before. At least I would expect an error or a warning.
Update:
I've tried the remove the braces and can confirm that, as I expected, it still don't work.
In fact I can confirm that this braces situation doesn't affect the code execution: I've put a very important chunk of code inside braces and the system still work exactly as expected.
Cheers.
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
I wasn't sure about the braces but that was a side note anyways.
I have looked at the emon-pi JeeInterfacer and it has been changed significantly from the working "experimental" version. For example this line has changed to this line without the trailing node id before the command it no longer conforms to JeeLib, this isn't an issue if you are wanting something bespoke but for portability across devices and to reach other nodes than the attached one, it would be better if the standard lib was used.
When the correctly formatted command string is passed over serial to an rfm2pi it is handled by this function, more specifically when sending using the "s" command via this line. The emonPi has a similar set up.
Since this code was written for transmitting to remote nodes rather than use in the attached device, (as it pre-dates even the rfm69pi and no IO was previously available on the rfm12pi) it will need to be caught before the RF transmission IF the base id node matches or it's a broadcast.
So ideally, this block needs expanding to include the logic to determine if it should be used locally, transmitted via rfm or both. I think this is the equivilent in emonPi.
Assuming you are using the [[[tx]]] section in [nodes] then the payload will need to match the typedef struct you set up to take the received frame at the emonpi.
A brief look at your example looks like it intends to use data received via rf rather than serial as the line starting " if (rf12_recvDone() " is handling the received rf payload rather than the serial stream.
What is your goal? will you replace the emonpi sketch with a bespoke sketch to handle your command or are you looking to retain the existing emonpi functions and add the command ability?
Paul
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Hi.
I'm making a function to receive the data I want using Serial.available() and Serial.read()
Now I only need to format the data back to it's format since it is received in ASCII.
Cheers.
Re: Transmit variables from EmonCMS (Rasp or external) to EmonPi
Hi.
I've managed to get it to work, I can now send at least one* variable from the local EmonCMS to Emonhub and receive it inside the EmonPI firmware.
I changed the handleInput function to my needs and it is working now.
I believe that there are some bugs in the emonhub software because it crashes when I send values above 32767 (the max positive number), but it shouldn't crash, I think. Anyway it works well enough for my needs.
* there is some bug here, if there is only one variable with more than one character in the name, it will create one variable for each character.
Now the question:
How do I update this variables from the remote EmonCMS (also in the local network) server that I use to make my logs and graphs?
In other words: how do I create a feed/node/output that calls the address on emonhub .../nodes/5/tx/values to update it's value?
Edit: It seems that what I want is Publish to MQTT, I'm now searching for the format of the Type Text Here related to Publish to the specified MQTT topic
Cheers.