ESP32 seems to be looped at the setup, it finishes all of it and then repeats it
Posted: Sat Dec 30, 2023 10:38 pm
ESP32 seems to be looped at the setup, it finishes all of it and then repeats it
Over and over again, i even downgrade the version of the board manager, cant figure it ou
The serial monitor looks like thi(repeats over and over again)
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
*wm:AutoConnect
*wm:Connecting to SAVED AP: IZZI-32FC
*wm:connectTimeout not set, ESP waitForConnectResult...
*wm:AutoConnect: SUCCESS
*wm:STA IP Address: 192.168.0.18
Connected to Wi-Fi!
Free heap: 212392
Before setupPruners()
Entering setupPruners()
setupruner2()
Code
main
#include "PrunerControl.h"
#include <HTTPClient.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ThingsBoard.h> // ThingsBoard SDK
#include <FS.h>
#include <esp_task_wdt.h>
// the number of the LED pin
// ThingsBoard parameters
#define THINGSBOARD_SERVER "demo.thingsboard.io"
#define TOKEN "6ZtLIhauqArq03Uo4zE4"
constexpr uint16_t THINGSBOARD_PORT = 1883U;
WiFiClient wifiClient;
WiFiManager wifiManager;
// Initialize ThingsBoard instance
ThingsBoard tb(wifiClient);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Try to connect to Wi-Fi using the global instance
if (!wifiManager.autoConnect("PrunerControllerBox")) {
Serial.println("Failed to connect");
// Optionally add a delay here to allow the user to see the message
// delay(5000);
// ESP.restart(); // Restart the device if unable to connect
}
else {
// If you get here, you have connected to Wi-Fi
Serial.println("Connected to Wi-Fi!");
Serial.print("Free heap: ");
Serial.println(ESP.getFreeHeap());
}
Serial.println("Before setupPruners()");
setupPruners();
Serial.println("After setupPruners()");
}
// Your existing pruner control loop
void loop() {
handleThingsBoardIntegration();
// ESP.wdtFeed();
}
// Handle ThingsBoard integration
void handleThingsBoardIntegration() {
// Check and reconnect to ThingsBoard if necessary
if (!tb.connected()) {
connectToThingsBoard();
subscribeToAttributes();
}
// Your existing pruner control logic
controlPruners();
// Send pruner status to ThingsBoard
tb.sendTelemetryData("Pruner1Status", stat1);
tb.sendTelemetryData("Pruner2Status", stat2);
delay(10);
// Handle ThingsBoard communication
//tb.loop();
}
// Connect to ThingsBoard
// Connect to ThingsBoard
void connectToThingsBoard() {
Serial.print("Connecting to ThingsBoard: ");
Serial.print(THINGSBOARD_SERVER);
Serial.print(" with token ");
Serial.println(TOKEN);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Serial.println("Failed to connect to ThingsBoard");
} else {
Serial.println("Connected to ThingsBoard");
}
}
// Subscribe to ThingsBoard attributes
void subscribeToAttributes() {
// Add your code to subscribe to attributes here
// For example:
// tb.subscribeToAttribute("Pruner1Attribute", onPruner1AttributeChange);
// tb.subscribeToAttribute("Pruner2Attribute", onPruner2AttributeChange);
}
void setupPruners() {
// configure LED PWM functionalities
Serial.println("Entering setupPruners()");
ledcSetup(Close, freq2, resolution1);
Serial.println("setupruner2()");
ledcSetup(Open, freq, resolution2);
Serial.println("setupruner3()");
pinMode(state1, INPUT);
Serial.println("setupruner4()");
pinMode(state2, INPUT);
Serial.println("setupruner5()");
Serial.println("PrunerSetup");
}
PrunerControl.h
// PrunerControl.h
#ifndef PRUNER_CONTROL_H
#define PRUNER_CONTROL_H
#include <driver/ledc.h>
extern int state1;
extern int state2;
extern bool stat1;
extern bool stat2;
extern int Pruner1;
extern int Pruner2;
// setting PWM properties
extern int freq;
extern int freq2;
extern int Open;
extern int Close;
extern int resolution1;
extern int resolution2;
//void setupPruners();
void controlPruners();
#endif
PrunerControl
// PrunerControl.cpp
#include "PrunerControl.h"
#include <Arduino.h>
#include <driver/ledc.h>
int state1 = 5;
int state2 = 10;
bool stat1 = HIGH;
bool stat2 = HIGH;
int Pruner1 = 2; // GPIO15
int Pruner2 = 18; // GPIO18
int freq = 3500; // OPEN
int freq2 = 7000; // CLOSE
int Open = 1;
int Close = 2;
int resolution1 = 10;
int resolution2 = 10;
void controlPruners() {
stat1 = digitalRead(state1);
stat2 = digitalRead(state2);
stat1=HIGH;
stat2=LOW;
Serial.println("Controlling");
// Check the states of the input pins
if (stat1 == HIGH) {
// If the input is HIGH, open Pruner 1
ledcAttachPin(Pruner1, Open);
ledcWrite(Open, 96);
Serial.println("OPEN");
} else {
// If the input is LOW, close Pruner 1
ledcAttachPin(Pruner1, Close);
ledcWrite(Close, 880);
}
if (stat2 == HIGH) {
// If the input is HIGH, open Pruner 2
ledcAttachPin(Pruner2, Open);
ledcWrite(Open, 96);
Serial.println("OPEN");
} else {
// If the input is LOW, close Pruner 2
ledcAttachPin(Pruner2, Close);
ledcWrite(Close, 880);
}
delay(1000); // Add a delay to observe the PWM effect
}
Over and over again, i even downgrade the version of the board manager, cant figure it ou
The serial monitor looks like thi(repeats over and over again)
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
*wm:AutoConnect
*wm:Connecting to SAVED AP: IZZI-32FC
*wm:connectTimeout not set, ESP waitForConnectResult...
*wm:AutoConnect: SUCCESS
*wm:STA IP Address: 192.168.0.18
Connected to Wi-Fi!
Free heap: 212392
Before setupPruners()
Entering setupPruners()
setupruner2()
Code
main
#include "PrunerControl.h"
#include <HTTPClient.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ThingsBoard.h> // ThingsBoard SDK
#include <FS.h>
#include <esp_task_wdt.h>
// the number of the LED pin
// ThingsBoard parameters
#define THINGSBOARD_SERVER "demo.thingsboard.io"
#define TOKEN "6ZtLIhauqArq03Uo4zE4"
constexpr uint16_t THINGSBOARD_PORT = 1883U;
WiFiClient wifiClient;
WiFiManager wifiManager;
// Initialize ThingsBoard instance
ThingsBoard tb(wifiClient);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Try to connect to Wi-Fi using the global instance
if (!wifiManager.autoConnect("PrunerControllerBox")) {
Serial.println("Failed to connect");
// Optionally add a delay here to allow the user to see the message
// delay(5000);
// ESP.restart(); // Restart the device if unable to connect
}
else {
// If you get here, you have connected to Wi-Fi
Serial.println("Connected to Wi-Fi!");
Serial.print("Free heap: ");
Serial.println(ESP.getFreeHeap());
}
Serial.println("Before setupPruners()");
setupPruners();
Serial.println("After setupPruners()");
}
// Your existing pruner control loop
void loop() {
handleThingsBoardIntegration();
// ESP.wdtFeed();
}
// Handle ThingsBoard integration
void handleThingsBoardIntegration() {
// Check and reconnect to ThingsBoard if necessary
if (!tb.connected()) {
connectToThingsBoard();
subscribeToAttributes();
}
// Your existing pruner control logic
controlPruners();
// Send pruner status to ThingsBoard
tb.sendTelemetryData("Pruner1Status", stat1);
tb.sendTelemetryData("Pruner2Status", stat2);
delay(10);
// Handle ThingsBoard communication
//tb.loop();
}
// Connect to ThingsBoard
// Connect to ThingsBoard
void connectToThingsBoard() {
Serial.print("Connecting to ThingsBoard: ");
Serial.print(THINGSBOARD_SERVER);
Serial.print(" with token ");
Serial.println(TOKEN);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
Serial.println("Failed to connect to ThingsBoard");
} else {
Serial.println("Connected to ThingsBoard");
}
}
// Subscribe to ThingsBoard attributes
void subscribeToAttributes() {
// Add your code to subscribe to attributes here
// For example:
// tb.subscribeToAttribute("Pruner1Attribute", onPruner1AttributeChange);
// tb.subscribeToAttribute("Pruner2Attribute", onPruner2AttributeChange);
}
void setupPruners() {
// configure LED PWM functionalities
Serial.println("Entering setupPruners()");
ledcSetup(Close, freq2, resolution1);
Serial.println("setupruner2()");
ledcSetup(Open, freq, resolution2);
Serial.println("setupruner3()");
pinMode(state1, INPUT);
Serial.println("setupruner4()");
pinMode(state2, INPUT);
Serial.println("setupruner5()");
Serial.println("PrunerSetup");
}
PrunerControl.h
// PrunerControl.h
#ifndef PRUNER_CONTROL_H
#define PRUNER_CONTROL_H
#include <driver/ledc.h>
extern int state1;
extern int state2;
extern bool stat1;
extern bool stat2;
extern int Pruner1;
extern int Pruner2;
// setting PWM properties
extern int freq;
extern int freq2;
extern int Open;
extern int Close;
extern int resolution1;
extern int resolution2;
//void setupPruners();
void controlPruners();
#endif
PrunerControl
// PrunerControl.cpp
#include "PrunerControl.h"
#include <Arduino.h>
#include <driver/ledc.h>
int state1 = 5;
int state2 = 10;
bool stat1 = HIGH;
bool stat2 = HIGH;
int Pruner1 = 2; // GPIO15
int Pruner2 = 18; // GPIO18
int freq = 3500; // OPEN
int freq2 = 7000; // CLOSE
int Open = 1;
int Close = 2;
int resolution1 = 10;
int resolution2 = 10;
void controlPruners() {
stat1 = digitalRead(state1);
stat2 = digitalRead(state2);
stat1=HIGH;
stat2=LOW;
Serial.println("Controlling");
// Check the states of the input pins
if (stat1 == HIGH) {
// If the input is HIGH, open Pruner 1
ledcAttachPin(Pruner1, Open);
ledcWrite(Open, 96);
Serial.println("OPEN");
} else {
// If the input is LOW, close Pruner 1
ledcAttachPin(Pruner1, Close);
ledcWrite(Close, 880);
}
if (stat2 == HIGH) {
// If the input is HIGH, open Pruner 2
ledcAttachPin(Pruner2, Open);
ledcWrite(Open, 96);
Serial.println("OPEN");
} else {
// If the input is LOW, close Pruner 2
ledcAttachPin(Pruner2, Close);
ledcWrite(Close, 880);
}
delay(1000); // Add a delay to observe the PWM effect
}