Created
May 22, 2018 05:56
-
-
Save moomdate/80d29a5f42656a141f5505828db083e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This example is meant to be used as a starting point | |
for working with Anto.io services | |
2017/06/17 | |
by Anto.io team | |
*/ | |
#include <AntoIO.h> | |
const char *ssid = "your access point SSID"; | |
const char *pass = "access point password"; | |
const char *user = "your username"; | |
const char *token = "your token"; | |
const char *thing = "your thing"; | |
// initialize AntoIO instance | |
AntoIO anto(user, token, thing); | |
int value = 0; | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
Serial.println(); | |
Serial.println(); | |
Serial.print("Anto library version: "); | |
Serial.println(anto.getVersion()); | |
Serial.print("\nTrying to connect "); | |
Serial.print(ssid); | |
Serial.println("..."); | |
anto.begin(ssid, pass, messageReceived); | |
Serial.println("\nConnected Anto done"); | |
//Subscript Channels | |
anto.sub("all"); | |
anto.sub("led1"); | |
anto.sub("led2"); | |
anto.sub("led3"); | |
anto.sub("led4"); | |
//Port output | |
pinMode(D1, OUTPUT); | |
pinMode(D2, OUTPUT); | |
pinMode(D3, OUTPUT); | |
pinMode(D4, OUTPUT); | |
} | |
void loop() { | |
anto.mqtt.loop(); | |
} | |
// a callback function for arriving data. | |
void messageReceived(String thing, String channel, String payload) { | |
Serial.print("Recieved: "); | |
Serial.print(thing); | |
Serial.print("/"); | |
Serial.print(channel); | |
Serial.print("-> "); | |
Serial.println(payload); | |
if (channel.equals("led1")) { | |
value = payload.toInt(); | |
if (value == 1) { | |
digitalWrite(D1, HIGH); | |
} | |
else { | |
digitalWrite(D1, LOW); | |
} | |
} | |
else if (channel.equals("led2")) { | |
value = payload.toInt(); | |
if (value == 1) { | |
digitalWrite(D2, HIGH); | |
} | |
else { | |
digitalWrite(D2, LOW); | |
} | |
} | |
else if (channel.equals("led3")) { | |
value = payload.toInt(); | |
if (value == 1) { | |
digitalWrite(D3 HIGH); | |
} | |
else { | |
digitalWrite(D3, LOW); | |
} | |
} | |
else if (channel.equals("all")) { | |
value = payload.toInt(); | |
if (value == 1) { | |
digitalWrite(D4, HIGH); | |
digitalWrite(D3, HIGH); | |
digitalWrite(D2, HIGH); | |
digitalWrite(D1, HIGH); | |
} | |
else { | |
digitalWrite(D4, LOW); | |
digitalWrite(D3, LOW); | |
digitalWrite(D2, LOW); | |
digitalWrite(D1, LOW); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment