Please I have the some problem and I don’t know how to solve it … could you help me to solve it, I would appreciate it from the heart
-
Wemos D1R1
-
Smartphone OS Android 10
-
blynk library v 1.0.0
-
local server
this is my code
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219_A(0x40);
BlynkTimer timer;
char ssid[] = "HUAWEI nova 5T";
char pass[] = "12345688";
char auth[] = "1j3YkPnBsVGfbsu8jG5-KiLSSDUGmvM3";
const char* mqtt_server = "192.168.43.73";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
void sendSensor() {
float Ashuntvoltage = 0;
float Abusvoltage = 0;
float Acurrent_mA = 0;
float Aloadvoltage = 0 ;
Ashuntvoltage = ina219_A.getShuntVoltage_mV();
Abusvoltage = ina219_A.getBusVoltage_V();
Acurrent_mA = ina219_A.getCurrent_mA();
Aloadvoltage = Abusvoltage + (Ashuntvoltage / 1000);
Blynk.virtualWrite(V0, Ashuntvoltage);
Blynk.virtualWrite(V1, Abusvoltage);
Blynk.virtualWrite(V2, Acurrent_mA);
Blynk.virtualWrite(V3, Aloadvoltage);
}
void setup() {
ina219_A.begin();
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
WiFi.begin(ssid, pass);
client.setServer(mqtt_server,1883);
}
void reconnect(){
while(!client.connected()){
if(client.connect("ESP8266client")){
Serial.print("connected");
}
else {
Serial.print("failed");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void loop()
{
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
if (!client.connected()){
reconnect();
}
client.loop();
long now = millis();
if (now - lastMsg > 1000){
lastMsg = now;
float arus = 0;
float volt = 0;
arus = ina219_A.getCurrent_mA();
volt = ina219_A.getBusVoltage_V();
char arusString[8];
dtostrf(arus, 1, 2, arusString);
Serial.print("Arus (mA) : ");
Serial.println(arusString);
client.publish("arus", arusString);
char voltString[8];
dtostrf(arus, 1, 2, voltString);
Serial.print("Tegangan (mA) : ");
Serial.println(voltString);
client.publish("volt", voltString);
}
}```