0

Set Up Feed to Change State of Toggle Switch?
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Set Up Feed to Change State of Toggle Switch?

by rfrei on Fri May 06, 2016 10:47 pm

I have an Arduino Mega 2560 connected to AIO's MQTT broker via an ethernet shield and its working great - I have (5) feeds up and running.

Tonight, I took things one step further and added a ZigBee network using XBee radios. The coordinator is connected to my Mega, and its talking to a single router on a remote breadboard. The radios are configured in AT command mode. All of this too is working great.

I have a toggle switch on my dashboard that controls a relay (via a transistor that's connected to a digital output pin on my router). The relay drives a lamp. There is some latency, and some messages get lost, but on average, the system is working well.

Question - I have a hard-wired switch connected to my Mega that's also controlling the relay circuit. Is it possible to synchronize the two switches (the switch on my dashboard and the hard-wired switch on my breadboard)? That is, can I send a message feed to the toggle switch on my AIO dashboard to keep it in sync with my hard-wired switch?

Help is much appreciated!

rfrei
 
Posts: 3
Joined: Fri May 06, 2016 12:24 am

Re: Set Up Feed to Change State of Toggle Switch?

by jasperp on Mon May 09, 2016 10:01 am

Yes, you need to update your feeds data from the Arduino end when you trigger the relay to keep them in sync. Currently you have one way communication setup.

Im currently trying to work out how to do something similar and iv made some head way so I can share with you what I have so far worked out.

Go to here
--> https://io.adafruit.com/api/docs/#!/Feeds/all

This allows you to play with IO Adafruits API. Enter your AIO in the top left before playing with the commands.

Go to DATA > ALL DATA FOR CURRENT FEED.

Press TRY and it will show a read out of Data you've posted to your feed. Find the ones relating to your "Relay Toggle" data updates and copy one of the data posts (Everything between { """"" } )

Example of mine
Code: Select all | TOGGLE FULL SIZE
  {
    "id": 490856479,
    "value": "TOGGLE",
    "position": null,
    "feed_id": 584808,
    "group_id": null,
    "expiration": null,
    "lat": null,
    "lon": null,
    "ele": null,
    "completed_at": null,
    "created_at": "2016-05-09T13:55:19.536Z",
    "updated_at": "2016-05-09T13:55:19.536Z",
    "created_epoch": 1462802119.53674
  }


Now you can attempt a manual update of the feed and make sure it triggers the relay as expected.

Go to DATA > CREATE NEW DATA
In Feed ID enter the Feed Name and under DATA 'PASTE' in one of those feed data updates you grabbed before which was for triggering the relay. It should manually trigger the relay/update your data feed with the current state of your switch.


NOW you need to use the Adafruit MQTT library to POST these updates you feed somehow. I plan on working that part out tomorrow night.

Let me know how your go and if you manage to work out how to POST your relays state to the feed, knowing Adafruits libraries its probably quite simple and there may be example sketches and code to look at and integrate into your project.

jasperp
 
Posts: 50
Joined: Mon May 27, 2013 5:06 am

Re: Set Up Feed to Change State of Toggle Switch?

by rfrei on Mon May 09, 2016 2:33 pm

Thanks much. I will try to play around with this after work tonight. Will report back.

rfrei
 
Posts: 3
Joined: Fri May 06, 2016 12:24 am

Re: Set Up Feed to Change State of Toggle Switch?

by jasperp on Tue May 10, 2016 12:34 am

Iv had a quick look at the MQTT library over lunch and im pretty sure updating your feed with your Arduinos relay status will be as simple as this
Code: Select all | TOGGLE FULL SIZE
mqttclient.publish(FEED_PATH, "relayStatus");

jasperp
 
Posts: 50
Joined: Mon May 27, 2013 5:06 am

Please be positive and constructive with your questions and comments.