Protokol MQTT
Zo stránky SensorWiki
MQTT cez Shiftr.IO
import mqtt.*;
MQTTClient client;
void setup()
{
client = new MQTTClient(this);
client.connect("mqtt://try:try@broker.shiftr.io", "Ferdinand");
}
void draw() { /* nerob nic, len cakaj na klavesu */}
void keyPressed()
{
client.publish("/feistu/BlokB/temperature", "27.0");
client.publish("/feistu/BlokB/humidity", "38.1");
client.publish("/feistu/BlokA", "InReconstruction...");
// client.publish("/feistu/misa/2020/XXX", "{\"XXX-Lat\": 49.1634, \"XXX-Lon\": 20.1349, \"XXX-Temp\": 18.2}");
}
void clientConnected() {
println("client connected");
client.subscribe("/feistu/#");
client.subscribe("/hello/#");
}
void messageReceived(String topic, byte[] payload) {
println("new message: " + topic + " - " + new String(payload));
}
void connectionLost() {
println("connection lost");
}
JSON
JSONObject message;
float temperature = 0.0;
int status = 0;
void setup()
{
message = new JSONObject();
message.setFloat("temperature", 10.0);
message.setInt("state",2);
message.setString("name", "Lion");
saveJSONObject(message, "data/new.json");
int aktualnyStav = message.getInt("state");
float aktualnaTeplota = message.getFloat("temperature");
String realName = message.getString("name");
println("Stav: " + aktualnyStav
+ ", Teplota: " + aktualnaTeplota + ", Meno: " + realName);
}
void draw() { /* nic nekreslime */ }
void keyPressed() {
temperature = random(-10, 32.5);
message.setFloat("temperature", temperature);
println(message.toString());
}