abouillot / HomeAutomation

Home Automation repository
84 stars 42 forks source link

Sending to RFM #7

Closed mhortman closed 9 years ago

mhortman commented 9 years ago

This is a great project. I have the Gateway program up and running. Seems quite stable and have had no problems with it.

I am now to the stage where I would like to have the Gatway subscribe to certain messages and send those back to nodes. It looks like there is a part of the code to handle subscriptions, but it is not quite there yet. Is that correct? Has anyone started working on something like that? If not, I am going to start.....

vador98 commented 9 years ago

I was able to add in my own code to handle subscriptions. It's not very robust, and I would have to hard code every message manually that I've subscribed to, but it works. The one thing that I've found is that the RFM69 does not transmit with much power. I'm not sure why, but the RSSI coming in is always much stronger than the received power that the gateway transmits. Here's the code I'm currently using:

I have this line just before the "setup complete" log message. This subscribes to topic 0112: mosquitto_subscribe(m,0,"0112",0);

Then in the "on_message" routine, I've placed the following, right after the LOG message: if (strcmp(msg->topic,"0112") == 0) { // Send msg->payload to sensor 41 theData.nodeID = 1; theData.sensorID = 41; theData.var1_usl = 0; theData.var2float = strtof((const char) msg->payload,NULL); theData.var3float = 0; rfm69->send(41,(const void)(&theData),sizeof(theData)); LOG("\nMessage sent to Camera Motion Detect Button\n"); }

Again, this is not a very elegant solution, but it's working for now. I'm currently in the process of switching to an Arduino gateway until the transmit issue can be resolved. I'm getting a lot of dropped packets which is somewhat critical for me. This should at least help get you moving in the right direction.

Good luck!

On Tue, Apr 7, 2015 at 11:09 PM, mhortman notifications@github.com wrote:

This is a great project. I have the Gateway program up and running. Seems quite stable and have had no problems with it.

I am now to the stage where I would like to have the Gatway subscribe to certain messages and send those back to nodes. It looks like there is a part of the code to handle subscriptions, but it is not quite there yet. Is that correct? Has anyone started working on something like that? If not, I am going to start.....

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7.

joshuarobot1 commented 9 years ago

I have a similar solution to @vador98. i have forked this repo and added my code if you want to look at it. it is no longer based on the current version though, but it is what i am using currently. https://github.com/joshuarobot1/HomeAutomation/tree/joshuarobot1-patch-1

SeldomCouth commented 9 years ago

Your issues with the Raspberry Pi gateway and transmit strength may be due to insufficient current for the radio. I know the RFM69HW needs 130ma at peak. Not sure about the non-HW model.

vador98 commented 9 years ago

That was my thought as well, but being attached to the pi, I'm not sure there's much we can do about that.   I've got my rfm module connected to the 3v pin on the pi- this might be a crazy suggestion, but is there a way to provide external power for the rfm module to try getting around the issue? — Sent from Mailbox

On Wed, Apr 8, 2015 at 12:15 AM, GitCouth notifications@github.com wrote:

Your issues with the Raspberry Pi gateway and transmit strength may be due to insufficient current for the radio. I know the RFM69HW needs 130ma at peak. Not sure about the non-HW model.

Reply to this email directly or view it on GitHub: https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90798513

abouillot commented 9 years ago

You can use a power converter taking the 5V (almost unlimited in power) to 3.3V such as http://www.tinydeal.com/fr/ams1117-33v-power-supply-module-blue-p-100548.html. I'm currently doing a test run with this setup to check if it improve anything.

mhortman commented 9 years ago

Would it make sense to have the node and the sensor embedded into the topic? I will write code to parse out the topic "/myhouse/NodeId/SensorId" and then put those items into the message?

Also, has anyone written the Arduino side of this to both send and receive the messages?

On Tue, Apr 7, 2015 at 10:43 PM, vador98 notifications@github.com wrote:

I was able to add in my own code to handle subscriptions. It's not very robust, and I would have to hard code every message manually that I've subscribed to, but it works. The one thing that I've found is that the RFM69 does not transmit with much power. I'm not sure why, but the RSSI coming in is always much stronger than the received power that the gateway transmits. Here's the code I'm currently using:

I have this line just before the "setup complete" log message. This subscribes to topic 0112: mosquitto_subscribe(m,0,"0112",0);

Then in the "on_message" routine, I've placed the following, right after the LOG message: if (strcmp(msg->topic,"0112") == 0) { // Send msg->payload to sensor 41 theData.nodeID = 1; theData.sensorID = 41; theData.var1_usl = 0; theData.var2float = strtof((const char) msg->payload,NULL); theData.var3float = 0; rfm69->send(41,(const void)(&theData),sizeof(theData)); LOG("\nMessage sent to Camera Motion Detect Button\n"); }

Again, this is not a very elegant solution, but it's working for now. I'm currently in the process of switching to an Arduino gateway until the transmit issue can be resolved. I'm getting a lot of dropped packets which is somewhat critical for me. This should at least help get you moving in the right direction.

Good luck!

On Tue, Apr 7, 2015 at 11:09 PM, mhortman notifications@github.com wrote:

This is a great project. I have the Gateway program up and running. Seems quite stable and have had no problems with it.

I am now to the stage where I would like to have the Gatway subscribe to certain messages and send those back to nodes. It looks like there is a part of the code to handle subscriptions, but it is not quite there yet. Is that correct? Has anyone started working on something like that? If not, I am going to start.....

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7.

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90795147 .

vador98 commented 9 years ago

I've also got this working on the arduino side. For the most part, you should be able to reference the "Gateway" and "Node" examples. That's where I stole my code from.

Here's the code I have for the receiving Arduino:

if (radio.receiveDone()) { if (int(radio.TARGETID) == 41){ theData = (Payload)radio.DATA; Serial.println(theData.var2_float); if ((int)theData.var2_float == 1) //Motion Detect is off { digitalWrite (redLED, LOW); digitalWrite (blueLED, LOW); digitalWrite (greenLED, HIGH); } else if ((int)theData.var2_float == 2) //Motion Detect is on { digitalWrite (greenLED, LOW); digitalWrite (blueLED, LOW); digitalWrite (redLED, HIGH); } else { digitalWrite (greenLED, LOW); digitalWrite (redLED, HIGH); digitalWrite (blueLED, HIGH); } } Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); }

Pretty simple, but that's all I personally need for now. Btw, I have this on a tri-color LED, so my red and blue shows as purple. ;-)

On Wed, Apr 8, 2015 at 11:49 AM, mhortman notifications@github.com wrote:

Would it make sense to have the node and the sensor embedded into the topic? I will write code to parse out the topic "/myhouse/NodeId/SensorId" and then put those items into the message?

Also, has anyone written the Arduino side of this to both send and receive the messages?

On Tue, Apr 7, 2015 at 10:43 PM, vador98 notifications@github.com wrote:

I was able to add in my own code to handle subscriptions. It's not very robust, and I would have to hard code every message manually that I've subscribed to, but it works. The one thing that I've found is that the RFM69 does not transmit with much power. I'm not sure why, but the RSSI coming in is always much stronger than the received power that the gateway transmits. Here's the code I'm currently using:

I have this line just before the "setup complete" log message. This subscribes to topic 0112: mosquitto_subscribe(m,0,"0112",0);

Then in the "on_message" routine, I've placed the following, right after the LOG message: if (strcmp(msg->topic,"0112") == 0) { // Send msg->payload to sensor 41 theData.nodeID = 1; theData.sensorID = 41; theData.var1_usl = 0; theData.var2float = strtof((const char) msg->payload,NULL); theData.var3float = 0; rfm69->send(41,(const void)(&theData),sizeof(theData)); LOG("\nMessage sent to Camera Motion Detect Button\n"); }

Again, this is not a very elegant solution, but it's working for now. I'm currently in the process of switching to an Arduino gateway until the transmit issue can be resolved. I'm getting a lot of dropped packets which is somewhat critical for me. This should at least help get you moving in the right direction.

Good luck!

On Tue, Apr 7, 2015 at 11:09 PM, mhortman notifications@github.com wrote:

This is a great project. I have the Gateway program up and running. Seems quite stable and have had no problems with it.

I am now to the stage where I would like to have the Gatway subscribe to certain messages and send those back to nodes. It looks like there is a part of the code to handle subscriptions, but it is not quite there yet. Is that correct? Has anyone started working on something like that? If not, I am going to start.....

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7.

— Reply to this email directly or view it on GitHub < https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90795147

.

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90957110 .

vador98 commented 9 years ago

And absolutely, it would make sense if the sensor and node were built into the topic. I am looking at some code written by computourist ( https://github.com/computourist/RFM69-MQTT-client). His solution appears to be complete and pretty elegant, using northbound messages from the sensors and southbound messages to send back to the sensors with everything built into the topic. It's a great implementation I would love to adopt, but that will take some effort to convert my current project over.

On Wed, Apr 8, 2015 at 11:49 AM, mhortman notifications@github.com wrote:

Would it make sense to have the node and the sensor embedded into the topic? I will write code to parse out the topic "/myhouse/NodeId/SensorId" and then put those items into the message?

Also, has anyone written the Arduino side of this to both send and receive the messages?

On Tue, Apr 7, 2015 at 10:43 PM, vador98 notifications@github.com wrote:

I was able to add in my own code to handle subscriptions. It's not very robust, and I would have to hard code every message manually that I've subscribed to, but it works. The one thing that I've found is that the RFM69 does not transmit with much power. I'm not sure why, but the RSSI coming in is always much stronger than the received power that the gateway transmits. Here's the code I'm currently using:

I have this line just before the "setup complete" log message. This subscribes to topic 0112: mosquitto_subscribe(m,0,"0112",0);

Then in the "on_message" routine, I've placed the following, right after the LOG message: if (strcmp(msg->topic,"0112") == 0) { // Send msg->payload to sensor 41 theData.nodeID = 1; theData.sensorID = 41; theData.var1_usl = 0; theData.var2float = strtof((const char) msg->payload,NULL); theData.var3float = 0; rfm69->send(41,(const void)(&theData),sizeof(theData)); LOG("\nMessage sent to Camera Motion Detect Button\n"); }

Again, this is not a very elegant solution, but it's working for now. I'm currently in the process of switching to an Arduino gateway until the transmit issue can be resolved. I'm getting a lot of dropped packets which is somewhat critical for me. This should at least help get you moving in the right direction.

Good luck!

On Tue, Apr 7, 2015 at 11:09 PM, mhortman notifications@github.com wrote:

This is a great project. I have the Gateway program up and running. Seems quite stable and have had no problems with it.

I am now to the stage where I would like to have the Gatway subscribe to certain messages and send those back to nodes. It looks like there is a part of the code to handle subscriptions, but it is not quite there yet. Is that correct? Has anyone started working on something like that? If not, I am going to start.....

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7.

— Reply to this email directly or view it on GitHub < https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90795147

.

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90957110 .

SeldomCouth commented 9 years ago

Yea, I really like the way his code handles the Northbound/Southbound content. I decided to use an Arduino gateway and let my Pi handle mosquitto, openHAB, sql, and some other stuff. But I'm still watching the Pi gateway efforts to see how things turn out.

vador98 commented 9 years ago

I'm dying to know if the power inverter has solved the problem with the transmit power. Very much looking forward to your results!

On Wed, Apr 8, 2015 at 6:50 AM, abouillot notifications@github.com wrote:

You can use a power converter taking the 5V (almost unlimited in power) to 3.3V such as http://www.tinydeal.com/fr/ams1117-33v-power-supply-module-blue-p-100548.html. I'm currently doing a test run with this setup to check if it improve anything.

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7#issuecomment-90878403 .

abouillot commented 9 years ago

Hi,

I'm seeing an improvement over the reliability of the communication between the radio and the Raspberry when using a RFM69HW module. Without it, on some occasion, the system ended up stop receiving, but not crashed.

However, not sure it would impact with RFM69W, as the max power indicated in datasheet is 45mA, bellow the 50mA supplied by raspberry.

Regarding bi-directionnal communication, I have the packets acknowledged properly (~97.5%) meaning the ack packet is properly sent from the raspberry.

I will dig further and check how to improve the success rate.

abouillot commented 9 years ago

I've updated the gateway and published a sample node code supporting bi-directional messages.

vador98 commented 9 years ago

I just tried this module on my pi, and at a distance of about 4 feet, I'm seeing an RSSI of -82 when transmitted from the pi. The RSSI when transmitted from the Arduino is -27. I don't think this quite solves the problem still.

On Mon, Apr 13, 2015 at 1:15 PM, Alexandre Bouillot < notifications@github.com> wrote:

Closed #7 https://github.com/abouillot/HomeAutomation/issues/7.

— Reply to this email directly or view it on GitHub https://github.com/abouillot/HomeAutomation/issues/7#event-279972072.