Hello guys i have some problem with my IoT project, im not sure its a bug or my failure.
The problem is, when i write code for connected to cayenne platform at this part
“Cayenne.begin(username, password, clientID, ssid, wifiPassword);”
my sensor can’t read properly. but when i delete this code my sensor can read properly, can someone help me please :((
this is the full code from my project:
/***************************************************
- INCLUDE !!!
****************************************************/
#include <SPI.h>
#include “ZMPT101B.h”
#include “ACS712.h”
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <CayenneMQTTESP32.h>/***************************************************
2. DEFINE !!!
**************************************************/
/ Define OLED Display/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);/* Define ZMPT101B */
ZMPT101B voltageSensor(14);/* Define ACS712_30A */
ACS712 currentSensor(ACS712_30A, 27);/* Define Cayenne */
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial/***************************************************
3. DECLARE !!!
****************************************************//* Declare ZMPT101B */
float VoltAC = 0;/* Declare ACS712 */
float AmpAC = 0;/* Declare Power */
float S = 0;
float P = 0;/* Declare Cayenne */
char ssid = “777”;
char wifiPassword = “blackshot1212”;
char username = “595fe320-f9f9-11e9-84bb-8f71124cfdfb”;
char password = “ca1601088df82b4ba32cbda89696559250bf7743”;
char clientID = “74fc22c0-39e0-11ea-8221-599f77add412”;/***************************************************
4. SETUP !!!
****************************************************/
void setup()
{Serial.begin(115200);
voltageSensor.calibrate();
currentSensor.calibrate();
/* Setup Cayenne */// /* Setup Sensor Calibrating */
// Serial.print(“Calibrating… Ensure that no current flows through the sensor at this moment”);
// // voltageSensor.calibrate();
// currentSensor.calibrate();
// Serial.println(“Done!”);/* Setup Display */
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F(“SSD1306 allocation failed”));
for (;;);
}
delay(2000);display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 10);
// Display static text
display.println(“MONITORING ARUS & kWh Meter”);
display.display();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);}
void loop()
{Cayenne.virtualWrite (1, VoltAC);
/Loop ZMPT101B/
VoltAC = abs(voltageSensor.getVoltageAC() - 6) * 1.8;/Loop ACS712/
Cayenne.virtualWrite (2, AmpAC);
AmpAC = abs(currentSensor.getCurrentAC() - 0.1) / 2.5;//perhitungan daya Semu
S = VoltAC * AmpAC;//perhitungan daya Aktif
P = S * 0.8;Cayenne.loop();
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(WHITE);display.setCursor(0, 0);
display.println(“TEGANGAN:”);
display.setCursor(60, 0);
display.println(VoltAC);
display.setCursor(100, 0);
display.println(“VOLT”);display.setCursor(127, 0);
display.println(“ARUS :”);
display.setCursor(60, 8);
display.println(AmpAC);
display.setCursor(100, 8);
display.println(“AMP”);display.setCursor(254, 16);
display.println(“DAYA AKTIF:”);
display.setCursor(381, 24);
display.println(P);
display.setCursor(100, 32);
display.println(“WATT”);
display.display();Serial.print(String("U = ") + VoltAC + " V ");
Serial.print(String("I = ") + AmpAC + " A ");
Serial.print(String("S = ") + S + " VA ");
Serial.println(String("P = “) + P + " Watts”);
delay(1000);}
This is the fail sensor
And this is the good one