0
\$\begingroup\$

I am not sure if this is the best community for this question, but I couldn't find one dedicated to IoT. Or should I ask on StackOverflow?

I am looking to build the following IoT system using WiFi devices: -- total 3 wifi capable devices -- devices #1 and #2 are acting as sensors. Assume they are simple ON-OFF type sensors (very infrequent state change) -- Device #3 is acting as an actuator, controlling an output ON/OFF -- Required functionality: The Device #3 should turn its output ON, when both device #1 and #2 read 'ON' on their sensors

I have spent today searching for ways to achieve this. I looked through Particle Photon, Sparkfun Thing, etc. for the devices and Thingspeak, data.sparfun.com for the cloud/internet part of it. But I couldnt see how I could achieve this. What is not clear to me is: --- how to get the message to the actuator device to turn its output ON?? Poll or send a message? how to do either?

Here is one potential approach I thought of:

  1. Use Sparkfun Thing for the devices
  2. The sensor devices use HTTP to post the sensor data to the cloud when they detect a change on their sensors values
  3. The actuator device, will periodically poll (by issuing HTTP GET requests) the cloud and fetch the sensors' data. And when it sees both are ON, it will drive its output ON

The problem with this is that I need quick reaction, i.e. once both the sensors read ON, I need the actuator to turn the output ON within 2-3 seconds. This means, with the "polling" method, I need to poll quite frequently, and I am not sure whether the rate-limits on Thingspeak and data.sparkfun.com will allow this.

So to summarize my questions: --- how to get the message to the actuator device to turn its output ON?? Is there a way other than polling, where a message can be sent to the device? --- Any suggestions on which platform (photon, sparkfun thing or any other) to use for this kind of project --- Any other (even totally different) suggestions on how to achieve the system with the required functionality described above

Thank you.

\$\endgroup\$
  • \$\begingroup\$ Is this all within a home LAN system? Or how are the units distributed? And yes, there are lots of different ways of messaging. So there isn't only one way to get this done. \$\endgroup\$ – jonk Oct 23 '16 at 3:55
  • \$\begingroup\$ All the devices will be on the same local wifi network \$\endgroup\$ – O.K. Oct 23 '16 at 3:56
  • \$\begingroup\$ Then I don't see much of a problem. Each one sets themselves up with your router to get an assigned IP. It's probably better if you program the MAC address of the host (your #3, I guess) into your router so that it always gets the same IP address to make things easier to code. Then your other devices just use that IP address all the time and communicate with the host when there are switch changes. That's with TCP/IP. You can also just use UDP, if you want. \$\endgroup\$ – jonk Oct 23 '16 at 4:00
3
\$\begingroup\$

If I were you, I would use MQTT messaging protocol. It is simple and easy to use. But it requires a broker (server) machine to work. I recommend reading this article about MQTT. Also it is really easy to add more sensor to the system.

Your system should be like this if you use MQTT:

  • Device #1, #2: "publishers", they are in deep-sleep for the most of the time (WiFi devices are really power hungry, they can consume about 200mA during data transmission). They only wake up on sensor state change and then publish their states (let's call them "ON1", "ON2", "OFF1", "OFF2") to a topic (let's call it "Status").
  • Device #3: "subscriber", it subscribes to "Status" topic and checks if the last two message were "ON1" and "ON2". Messages arrive "immediately" when using MQTT protocol, so creating a callback function on receiving a message will be fast enough to achive 2-3 second respond time (in fact it will be much more faster).

  • MQTT broker, for example a Raspberry Pi or an online one like this, used to host topic(s).

Note that if you are using a LAN, not an online, broker, it also can work as Device #3 ("subscriber").

\$\endgroup\$
  • \$\begingroup\$ thanks! this was very useful and a big TIL for me ... I read through some online tutorials etc. One question I have is -- To save power on my Subscriber, I need to put it to sleep and wake up periodically (every 2 secs) or so, correct ? But to make sure it receives the status (perhaps sent by the publisher while the subscriber was asleep), I need to use QoS 1, correct? Or is there another better way? \$\endgroup\$ – O.K. Oct 23 '16 at 20:37
  • \$\begingroup\$ Yes QoS 1 is what you should use. But I would not put my Subscriber to deep-sleep, I would rather use LAN broker and use it as my Subscriber. Or assuming that you will use Sparkfun Thing you can check other power saving and sleep modes here. \$\endgroup\$ – Bendegúz Szatmári Oct 23 '16 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.