The following example is presented in order to show you how to send messages from arduino,
#include "abtoo.h"
int ledPin = 13; // GPIO13
char* ssid = "homessid";
char* password = "mypassword";
int h = LOW;
AbetooIno abtoino;
void messageReceived(String message)
{
Serial.println(message);
h = h^1;
digitalWrite(ledPin, h?HIGH:LOW);
}
void setup() {
Serial.begin(9600);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
String uuid = "uudi1";
String channel = "-TbVO-rqdA0iWg6-gWh0eeQ636243460528994051"
"#735acf9cd6eda96e66ee3858496dca59d750aff1";
int heartbeat = 1; // minutes
abtoino.init(uuid, channel, heartbeat, messageReceived);
}
String channeltarget = "-uC6s1LfZaEuw9AK0Js1w9w636243459698606497#"
"b90a9186b9b61ead17d51251f689aea1779d5203";
long count = 0;
long messages = 0;
void loop()
{
if (count++ == 1000000)
{
count = 0;
String body = "Message from arduino ";
body = body + (messages++) + "!";
abtoino.sendMessage(channeltarget, body, "no correlation id");
}
abtoino.abetooloop();
}
There is only a new piece of code where the sending process take place,
String channeltarget = "-uC6s1LfZaEuw9AK0Js1w9w636243459698606497#"
"b90a9186b9b61ead17d51251f689aea1779d5203";
long count = 0;
long messages = 0;
void loop()
{
if (count++ == 1000000)
{
count = 0;
String body = "Message from arduino ";
body = body + (messages++) + "!";
abtoino.sendMessage(channeltarget, body, "no correlation id");
}
abtoino.abetooloop();
}
We have to define a target channel id, a message body and an optional correlation id.
Once every 1000000 loop iterations a message is sent to the target channel id.
To ilustrate the functionality exposed above I’m going to show you an example with a target device based on the xamarin android code.
Leave A Comment?