The code for both the sender (Arduino) and the receiver (Raspberry Pi) is in my github repo. The comments in the code pretty much explain everything (how it works, how to connect the sensors and radios, and so on). Here are just some quick ideas that may be interesting.
- I wanted to transmit all the data in one go so I combined 4 numbers into one long, as described in both sender and receiver code.
- The transmission between the radios is pretty flaky, that's why I am repeating the send a lot on the Arduino and there is code on the receiver to ignore identical values coming in a 30s interval. This is OK because transmissions from different stations have different station codes so even if the sensor values are the same, the actual overall value is different. Same for a motion sensor: the ON value is different than the OFF value so even if they happen a second apart, both will be received.
- I started by posting the data to SparkFun's data service, then added Dweet.io and in the end settled on ThingSpeak and I'm also saving all the data to a local SQLite database. See some notes about this later in this post.
- The code in github is ready to use: just change the stationCode for each Arduino station and use the right API keys in the Raspberry Pi code.
Rate limits:
- SparkFun's data service is limited to making 100 log requests every 15 minutes. Given the 5 posts in 15 min, the temperature data stream can accommodate 20 stations without losing data which is more than I need. The motion data though may accommodate only 1 or 2 stations (more if there is not a lot of activity around them) without starting to lose data. I will post all the data I can, the remainder being lost.
- Dweet.io holds on to the last 500 dweets over a 24 hour period so while there won't be data loss, the motion data will probably cover only a few hours at the most, even for just a couple stations.
- ThingSpeak has a rate limit of an update per channel every 15 seconds so more than one station per channel will more than likely run into this limit (even 2 temp stations sending data every 15 minutes can happen to send data less than 15 sec apart); I could wait and retry until the post goes through but this would delay the code and risk missing data sent by the stations. Because of this, I decided to tie the local db data to this service: every time I post to ThingSpeak, I check the response: if > 0, the post was successful, I will log the data to the db with a flag of posted=true (1); if = 0, the post was not successful so I will log the data to the db with a flag of posted=false (0). Later I may create a node-red flow to get all the db data with posted=false and repost it to ThingSpeak; each row records the UTC time of the actual insert so I can send it along with the data, the measurements getting recorded at the actual time they took place not the time I post them.
15 comments:
This is absolutely great! Since getting my Raspberry Pi two months ago, I was looking to do some home automation / security and incorporate some sensor logging. I wasn't really interested in copying anyone elses solutions but yours fits the bill so perfectly I can't see the point in reinventing the wheel. One question (for now) the data word that the Arduino sends are all of the bits used or is there spare capacity to add other sensors onto each node.
Thanks Ray
Thanks a lot for your kind words!
As far as your question, I am using all the bits so for more sensors you may need more than one transmission.
Hi,can you tell me the code that you use for receiving data from arduino,because my raspberry pi shows only some numbers
Gabriela, most of the code is in my repo, mentioned in the article. Is there anything in particular I can help you with?
i got problem only receive 268435457 1-0-0-1 and 268435456 1-0-0-0 from ./RFRcvCmplxData
never get temperature,humidity and voltage..
but arduino serial monitor output
Humidity: 69.00 % Temperature: 29.00 *C 84.20 *F Heat index: 90.58 *F
batt: 93
DHT: 268435549
PIR: 268435457
10000000000000000000000000001
Humidity: 69.00 % Temperature: 29.00 *C 84.20 *F Heat index: 90.58 *F
batt: 93
DHT: 268435549
PIR: 268435457
10000000000000000000000000001
resolve the issue adding humid=h; and temp=t;
float hi = dht.computeHeatIndex(f, h);
Serial.print("Humidity: ");
Serial.print(h);
humid=h;
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
temp=t;
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
}
Sorry I didn't have time to look into it, I am happy you found a solution.
right now got problem MQTT error 14 after long run ./RFRcvCmplxData
dont know how to figure out adding mosquitto_loop_start if connection to MQTT broker drop and reconnect
many thanks to you for sharing this project....i so interested :)
I had problems as well using mqtt, since this was my first time using the library I figured I am missing something and never had time to go back to find out what was wrong. If you do find a solution, please post a link to a gist or your github repo. Thanks!
im already figure out that error 14...im combine script in 433Mhz-Arduino/RFRcvCmplxData.cpp + /mqtt/RFRcvCmplxData.cpp so it send MQTT plus update thingspeaks at once
res variable used 2 times so it conflict...now rename it to res1 for all curl res variable.
now im trying to solve issue auto reconnect to mqtt broken...
testing stop and then start my mqtt broker it seem it not auto reconnect to broker
for ur info im new to programming and linux
Awsome project!
Thanks for sharing it. It took me quite some time to figure a lot of stuff out, but I'm almost up and running.
I'm running in to a small problem with the MQTT part of it.
when running RFMqttRcvCmplxData It's kind of stuck at 'Client client_1 sending CONNECT' and I would like some pointers on how to proceed. Mosquitto seems to be working fine.
Unfortunately, I don't have any idea why your message is not sent. As I commented in my code, I've seen notes on the web about using mosquitto_loop() to make sure all your messages are sent but I never got to look into the details. I hope you will be able to make it work.
Thanks a lot for your kind words!
Post a Comment