hi
I am using esp32 dev to send 10 variables to free account ubidots using MQTT using the code
/****************************************
Include Libraries
****************************************/
#include “UbidotsEsp32Mqtt.h”
#include <WiFi.h>
#include <dht.h> //DHT Senser
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include “EmonLib.h” // Include Emon Library
/****************************************
Define Constants
****************************************/
const char *UBIDOTS_TOKEN = “BBFF - mbcxHDE7WbYa”; // Put here your Ubidots TOKEN
const char *WIFI_SSID = “Jaafar”; // Put here your Wi-Fi SSID
const char *WIFI_PASS = “001122391100”; // Put here your Wi-Fi password
const char *DEVICE_LABEL = “SCADA”; // Put here your Device label to which data will be published
const char *VARIABLE_LABEL = “temp”; // Put here your Variable label to temprture which data will be published
const char *VARIABLE_LABEL1 = “pv-voltaqge”; // Put here your Variable label to pv voltage which data will be published
const char *VARIABLE_LABEL2 = “pv-current”; // Put here your Variable label to pv voltage which data will be published
const char *VARIABLE_LABEL3 = “pv-power”; // Put here your Variable label to pv power which data will be published
const char *VARIABLE_LABEL4 = “battery-voltage”; // Put here your Variable label to battery voltage which data will be published
const char *VARIABLE_LABEL5 = “battery-current”; // Put here your Variable label to battery current which data will be published
const char *VARIABLE_LABEL6 = “battery-power”; // Put here your Variable label to battery power which data will be published
const int PUBLISH_FREQUENCY = 500; // Update rate in milliseconds
unsigned long timer;
Ubidots ubidots(UBIDOTS_TOKEN);
#define dht_apin 27 // Analog Pin sensor is connected to temprtut 27
dht DHT;
#define VOLT_CAL 190
EnergyMonitor emon1; // Create an instance
#define NUMSAMPLES 5
int sensorValue;
int curr_samples[NUMSAMPLES];
/*
PIN CONNECTIONS SENSOR
S → A3 green
→ 5V red
→ GND blue
Calculate exact values with multimeter:
Vin on adapter = 12.41V
Vout on Arduino = 2.42
5V on Arduino = 5.10V
Vin / vOut = factor
12.41 / 2.42 = 5.128
*/
const int voltageSensorPin = A3; // dc pv sensor pin
const int voltageSensorPin1 = A0; // dc battery sensor pin
float vIn; // measured voltage (3.3V = max. 16.5V, 5V = max 25V)
float pvp;
float bp;
float Vbattery; // measured voltage (3.3V = max. 16.5V, 5V = max 25V)
float vOut;
float vOut1;
float voltageSensorVal; // value on pin A3 (0 - 1023) for esp (0-4096) ADC resolution for pv
float voltageSensorVal1; // value on pin A3 (0 - 1023) for esp (0-4096) ADC resolution for battery
const float factor = 5.128; // reduction factor of the Voltage pv dc Sensor shield
const float factor1 = 5.128; // reduction factor of the Voltage battery dc Sensor shield
const float vCC = 3.30; // Arduino input voltage (measurable by voltmeter) for esp32 =3.3
const int sensorIn = A4;
float Voltage = 0;
float VRMS = 0;
float AmpsRMS = 0;
float getVPP();
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
// pv dc current sonser
const int currentPin = 33;
int sensitivity = 66;
int adcValue = 0;
int offsetVoltage = 2168;
float adcVoltage = 0;
float currentValue = 0;
// battery dc current sonser
const int currentPin1 = 35;
int sensitivity1 = 66;
int adcValue1 = 0;
int offsetVoltage1 = 2168;
float adcVoltage1 = 0;
float currentValue1 = 0;
// the value of the ‘other’ resistor
#define SERIESRESISTOR 10000
// define Analog for Current and Voltage
const int curr_an_pin = 35;
int count = 0;
/****************************************
Auxiliar Functions
****************************************/
void callback(char *topic, byte *payload, unsigned int length) {
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
/****************************************
Main Functions
****************************************/
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// ubidots.setDebug(true); // uncomment this to make debug messages available
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
ubidots.setCallback(callback);
ubidots.setup();
ubidots.reconnect();
timer = millis();
}
void loop() {
// put your main code here, to run repeatedly:
if (!ubidots.connected()) {
ubidots.reconnect();
}
if (abs(millis() - timer) > PUBLISH_FREQUENCY) // triggers the routine every 5 seconds
{
// Start of Program temprture
DHT.read11(dht_apin);
float tem = (DHT.temperature);
Serial.print(" humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(1000); // Wait 1 seconds before accessing sensor again.
// end sonser temprture
// start dc pv voltage sonser
voltageSensorVal = analogRead(voltageSensorPin); // read the current sensor value (0 - 1023) for ard and 0-4096 for esp32
vOut = (voltageSensorVal / 4096) * vCC; // convert the value to the real voltage on the analog pin
vIn = vOut * factor; // convert the voltage on the source by multiplying with the factor
delay(1000);
// end dc pv voltage sonser
// start pv dc current sonser
{
adcValue = analogRead(currentPin);
adcVoltage = (adcValue / 4096.0) * 5200;
currentValue = ((adcVoltage - offsetVoltage) / sensitivity);
delay(1000);
}
// end pv dc current sonser
// start dc pv power
pvp = vIn * currentValue;
// end dc pv power
// start dc battery voltage sonser
voltageSensorVal1 = analogRead(voltageSensorPin1); // read the current sensor value (0 - 1023) for ard and 0-4096 for esp32
vOut1 = (voltageSensorVal1 / 4096) * vCC; // convert the value to the real voltage on the analog pin
Vbattery = vOut1 * factor1; // convert the voltage on the source by multiplying with the factor
delay(1000);
// end dc battery voltage sonser
// start dc battery current sonser
{
adcValue1 = analogRead(currentPin1);
adcVoltage1 = (adcValue1 / 4096.0) * 5200;
currentValue1 = ((adcVoltage1 - offsetVoltage1) / sensitivity1);
delay(1000);
}
// end dc battery current sonser
// start dc battery power
bp = Vbattery * currentValue1;
// end dc battery power
Serial.print("Solar Voltage = ");
Serial.print(vIn);
Serial.println(“V”);
Serial.print("Solar Current = ");
Serial.print(currentValue);
Serial.println(“A”);
Serial.print("Solar Power = ");
Serial.print(pvp);
Serial.println(“W”);
Serial.print("Battery Voltage = ");
Serial.print(Vbattery);
Serial.println(“V”);
Serial.print("battery Current = ");
Serial.print(currentValue1);
Serial.println(“A”);
Serial.print("Battery Power = ");
Serial.print(bp);
Serial.println(“W”);
ubidots.add(VARIABLE_LABEL, tem); // Insert your variable Labels temprture and the value to be sent
ubidots.add(VARIABLE_LABEL1, vIn); // Insert your variable Labels dc pv voltage and the value to be sent
ubidots.add(VARIABLE_LABEL2, currentValue); // Insert your variable Labels dc pv current and the value to be sent
ubidots.add(VARIABLE_LABEL3, pvp); // Insert your variable Labels dc pv power and the value to be sent
ubidots.add(VARIABLE_LABEL5, currentValue1); // Insert your variable Labels dc battery current and the value to be sent
ubidots.add(VARIABLE_LABEL6, bp); // Insert your variable Labels dc pv power and the value to be sent
ubidots.publish(DEVICE_LABEL);
timer = millis();
}
ubidots.loop();
}
if increase variable the site don’t receive data