

mosquitto_sub -d -t Moisture
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script> onInit: function() {
this.aSearchFilters = [];
this.aTabFilters = [];
this.client = new Paho.MQTT.Client("192.168.29.3", 9001, "nabheet");
this.client.onConnectionLost = this.onConnectionLost;
this.client.onMessageArrived = this.onMessageArrived.bind(this);
this.client.connect({
useSSL: false,
onSuccess: this.onConnect.bind(this)
}); onMessageArrived:function(message) {
try {
console.log("Recieved Message from server");
var value = message.payloadString;
var datastream = message.destinationName;
console.log("datastream: " + datastream + ", value: " + value);
var oModel = this.getView().getModel();
var aTodos = oModel.getProperty("/todos").map(function (oTodo) { return Object.assign({}, oTodo); });
// Use of Date.now() function
var d = Date(Date.now());
// Converting the number of millisecond in date string
var a = d.toString()
aTodos.push({
title: value,
completed: false,
time:a
});
oModel.setProperty("/todos", aTodos);
oModel.setProperty("/newTodo", "");
} catch (e) {
console.log("exception in onMessageArrived: " + e);
return false;
}
},
onConnect: function () {
console.log("Connected to server");
this.client.subscribe("Moisture");
},mosquitto_pub -d -t Mositure -m "Hello World!"

pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());// Make sure to update this for your own MQTT Broker!
const char* mqtt_server = "192.168.29.3";
const char* mqtt_topic = "Moisture";
const char* clientID = "M1";
PubSubClient client(mqtt_server, 1883, wifiClient); // 1883 is the listener port for the Broker float moisture_percentage;
moisture_percentage = ( 100.00 - ( (analogRead(sensor_pin)/1023.00) * 100.00 ) );
String msg = String(moisture_percentage);
if (client.publish(mqtt_topic, msg.c_str())) {
Serial.println("Message Sent!");
Serial.println(msg);
Serial.println(msg.c_str());
}You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 13 | |
| 12 | |
| 12 | |
| 11 | |
| 11 | |
| 11 | |
| 10 | |
| 10 |