IoT based Liquid level Monitoring using ESP32 board and Qubitro IoT Portal
Hello Everyone! IoT based Liquid level Monitoring using ESP32 board and Qubitro IoT Portal In this video what you will learn about? 1. How to configure the new Qubitro Iot Platform. 2. How to Create new project on Qubitro IoT Platform. 4. How to Create Dashboard for Monitoring data. 5. How to Interface the Ultrasonic sensor with ESP32. 6. How to do the programming for the ESP32. #Qubitro #IoT
Circuit Diagram:
Code:
[Note :you need to install the QubitroMqttClient.h library]
you can download the library click here Download
#include <QubitroMqttClient.h>
#include <WiFi.h>
#define trig 5 // Trig pin
#define echo 18
int duration;
int distance;
// WiFi Client
WiFiClient wifiClient;
// Qubitro Client
QubitroMqttClient mqttClient(wifiClient);
// Device Parameters
char deviceID[] = "5060befb-5aec-4777-b247-4c11ce884a54";
char deviceToken[] = "IeqcXR0zhmhHpbmf-mt8t1w$9FAg3-gutaMd-0$J";
// WiFi Parameters
const char* ssid = "impulsetech";
const char* password = "impulse567";
void setup() {
// Initialize the serial port
serial_init();
// Initialize wireless connectivity
wifi_init();
// Initialize Qubitro
qubitro_init();
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance= duration*0.034/2;
//Serial.println(distance);
delay(100);
// Generate random values
int sensor_value_1 = distance;
int sensor_value_2 = random(0, 100);
// Print the random values
Serial.print("Sensor value 1: ");
Serial.println(sensor_value_1);
Serial.print("Sensor value 2: ");
Serial.println(sensor_value_2);
// Send telemetry
String payload = "{\"Sensor 1\":" + String(sensor_value_1)
+ ",\"Sensor 2\":" + String(sensor_value_2) + "}";
mqttClient.poll();
mqttClient.beginMessage(deviceID);
mqttClient.print(payload);
mqttClient.endMessage();
// Delay
delay(2000);
}
// Initialization code
void serial_init() {
// Initiate serial port connection
Serial.begin(115200);
// Delay for stabilization
delay(200);
}
void wifi_init() {
// Set WiFi mode
WiFi.mode(WIFI_STA);
// Disconnect WiFi
WiFi.disconnect();
delay(100);
// Initiate WiFi connection
WiFi.begin(ssid, password);
// Print connectivity status to the terminal
Serial.print("Connecting to WiFi...");
while(true)
{
delay(1000);
Serial.print(".");
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("");
Serial.println("WiFi Connected.");
Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
break;
}
}
}
void qubitro_init() {
char host[] = "broker.qubitro.com";
int port = 1883;
mqttClient.setId(deviceID);
mqttClient.setDeviceIdToken(deviceID, deviceToken);
Serial.println("Connecting to Qubitro...");
if (!mqttClient.connect(host, port))
{
Serial.print("Connection failed. Error code: ");
Serial.println(mqttClient.connectError());
Serial.println("Visit docs.qubitro.com or create a new issue on github.com/qubitro");
}
Serial.println("Connected to Qubitro.");
mqttClient.subscribe(deviceID);
}
Comments
Post a Comment
If you any query please comment