hey, i have created a dashboard on Blynk to read data from 4 gas sensors using Esp32. The problem is that i got the same value on the widgets as a result (500) but when u click in modify the widget values changes and also the graphs. in fact when modifying its the correct values that shows up but when i click in save to get my dashboard it comes back to the 500 for the 4 sensors
Mobile or web dashboard?
If mobile, the Android or iOS, and which app version?
How are your datastreams configured?
What does your code look like?
Are you sending the readings to the serial monitor, if so, what do they look like?
When you created this topic you were prompted to provide some of this information, is there any reason why you didn’t?:
Pete.
it is a web dashboard. i configured the datastreams using virtual pins: a virtual pin for every sensor .
and her is the code :
[Unformatted code removed by moderator]
@selmansir Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
Copy and paste these if you can’t find the correct symbol on your keyboard.
Pete.
#define BLYNK_TEMPLATE_NAME "*************"
#define BLYNK_AUTH_TOKEN "******************"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <PubSubClient.h>
char auth[] = BLYNK_AUTH_TOKEN;
// WiFi credentials
char ssid[] = "***************";
char pass[] = "**************";
// MQTT broker details
const char* mqtt_server = "broker.hivemq.com";
const int mqtt_port = 1883;
const char* mqtt_user = "";
const char* mqtt_pass = "";
// MQTT topics for each sensor
const char* topic_mq3 = "home/gasSensor/MQ3";
const char* topic_mq7 = "home/gasSensor/MQ7";
const char* topic_mq135 = "home/gasSensor/MQ135";
const char* topic_mq4 = "home/gasSensor/MQ4";
WiFiClient espClient;
PubSubClient client(espClient);
BlynkTimer timer;
// Define the analog pins for the MQ sensors
const int MQ3_PIN = 39;
const int MQ7_PIN = 35;
const int MQ135_PIN = 36;
const int MQ4_PIN = 34;
#define ALCOHOL_THRESHOLD 200
#define BENZENE_THRESHOLD 200
#define METHANE_THRESHOLD 200
#define CO_THRESHOLD 50
void sendSensorData() {
// Read the analog values from the sensors
int mq3_value = analogRead(MQ3_PIN);
int mq7_value = analogRead(MQ7_PIN);
int mq135_value = analogRead(MQ135_PIN);
int mq4_value = analogRead(MQ4_PIN);
// Send the data to the Blynk virtual pins
Blynk.virtualWrite(V0, mq3_value);
Blynk.virtualWrite(V3, mq7_value);
Blynk.virtualWrite(V1, mq135_value);
Blynk.virtualWrite(V2, mq4_value);
// Publish the sensor data to MQTT topics
client.publish(topic_mq3, String(mq3_value).c_str());
client.publish(topic_mq7, String(mq7_value).c_str());
client.publish(topic_mq135, String(mq135_value).c_str());
client.publish(topic_mq4, String(mq4_value).c_str());
// Print the sensor values to the Serial Monitor
Serial.print("MQ3: "); Serial.print(mq3_value);
Serial.print(" MQ7: "); Serial.print(mq7_value);
Serial.print(" MQ135: "); Serial.print(mq135_value);
Serial.print(" MQ4: "); Serial.println(mq4_value);
}
void setup() {
// Initialize the Serial Monitor
Serial.begin(115200);
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Set up MQTT client
client.setServer(mqtt_server, mqtt_port);
// Setup a timer to send sensor data every second
timer.setInterval(1000L, sendSensorData);
}
void loop() {
// Run Blynk and timer
Blynk.run();
timer.run();
client.loop(); // Maintain MQTT connection
// Read sensor values
int alcoholLevel = analogRead(MQ3_PIN);
int benzeneLevel = analogRead(MQ135_PIN);
int methaneLevel = analogRead(MQ4_PIN);
int COLevel = analogRead(MQ7_PIN);
// Print and check sensor values
Serial.print("Niveau d'alcool en mg/L : ");
Serial.println(alcoholLevel);
if (alcoholLevel > ALCOHOL_THRESHOLD) {
Blynk.logEvent("alcool_alert", "Niveau d'alcool élevé!");
}
Serial.print("Niveau de benzene en mg/L : ");
Serial.println(benzeneLevel);
if (benzeneLevel > BENZENE_THRESHOLD) {
Blynk.logEvent("benzene_alert", "Niveau de benzène élevé!");
}
Serial.print("Niveau de methane en ppm : ");
Serial.println(methaneLevel);
if (methaneLevel > METHANE_THRESHOLD) {
Blynk.logEvent("methane_alert", "Niveau de methane élevé!");
}
Serial.print("Niveau de CO en ppm : ");
Serial.println(COLevel);
if (COLevel > CO_THRESHOLD) {
Blynk.logEvent("co_alert", "Niveau du monoxyde de carbone élevé!");
}
}
thank you for your response
I asked the question…
and your response was…
I’d expected/needed more information than that. Please provide details of how your datastreams are configured.
I also asked…
I see from your code that you are indeed sensing the values to your serial monitor, but you’ve not provided any information about the values you’re seeing there.
If you want to share your serial output (which would obviously be useful) then please copy the text from your serial monitor and paste it with triple backticks at the beginning and end. Please don’t post a screenshot of your serial monitor output.
There are still lots of unanswered questions, which you were prompted to answer when you created this topic. I assume you feel that this information is irrelevant, but providing, and providing full answers to the questions that are asked, is more likely to result in a speedy resolution to your issue.
Pete.