Hello World

This program would connect to a mqtt server, to an especif topic and send "Hello World" as message each time you press a button.

  1. Create a new XDK Live project.

  2. 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
}

Test

Open a terminal and execute

# mosquitto_sub -h broker.hivemq.com -p 1883 -t XDK/RBTest

*You need to change for your topic, and already have install mosquitto in your machine

Last updated

Was this helpful?