This program would connect to a mqtt server, to an especif topic and send "Hello World" as message each time you press a button.
Create a new XDK Live project.
Modify .x file
Code
/**
* Welcome to XDK LIVE.
*
* Not sure what to do now?
* Check out the "Getting started" guide in the Eclipse help.
*/
package main;
import platforms.xdk110;
// Create a wireless connection named 'wireless'
setup wireless : WLAN {
ssid = "Centraal-Comunidad";
ipConfiguration = Dhcp();
authentification = Personal(psk = "hoyemprendo");
}
// Create a MQTT instance
setup messaging : MQTT {
transport = wireless;
url = "mqtt://broker.hivemq.com:1883"; // Try differents brokers iot.eclipse.org, etc.
cleanSession = true;
clientId = "1234"; //Define your userID
var Test = topic("XDK/RBTest",1); //Define your own topic
}
// When button one is pressed, send text via MQTT
every button_one.pressed {
messaging.Test.write("Test Write"); //Define your message
}