None Notebook

This notebook contains material from cbe61622; content is available on Github.

< 3.2 Accessing a Remote Experiment via MQTT | Contents | 4.0 Signal Conditioning >

Open in Colab

Download

3.3 Accessing MQTT Devices

3.3.1 Installing paho-mqtt library

3.3.2 Particle Argon

The following code is flashed to the Particle Argon using the Particle Web IDE.

// Report temperature and humidity sensor. Provide a short blink of D7
// to indicate an temperture/humidity update.

#include <Grove_Temperature_And_Humidity_Sensor.h>
#include <MQTT.h>

int led = D7;
DHT dht(D2);

float temp, humidity;

void callback(char* topic, byte* payload, unsigned int length);
MQTT client("mqtt.eclipse.org", 1883, callback);

// receive message
void callback(char* topic, byte* payload, unsigned int length) {
}

void setup() {

    dht.begin();
    pinMode(led, OUTPUT);
    client.connect("argon_" + String(Time.now()));
}

void loop() {

    temp = dht.getTempFarenheit();
    humidity = dht.getHumidity();

    client.publish("cbe-virtual-laboratory/devices/argon", Time.timeStr() + ", " + String(temp, 1) + ", " + String(humidity, 1));

    digitalWrite(led, HIGH);
    delay(200);
    digitalWrite(led, LOW);
    delay(4800);
}

3.3.3 Receiving data from Particle Argon device

< 3.2 Accessing a Remote Experiment via MQTT | Contents | 4.0 Signal Conditioning >

Open in Colab

Download