Wifimanager 8266 move to esp32 always connected. Disconnects or drops connection - esp32

I have a project on a Wemos d1 mini. I am using the WiFi manager and for the most part works fine.
I have 2 issues I’m trying to fix:
I’m trying to move all the code to lolin esp d32. But the WiFi manager broadcasts the station only for a minute and then if I needed to connect to it I have to reset the board. Can someone help me resolve this issue so it works like I had it on the d1
when it was on the d1 it would disconnect or lose connection. Then I would have to tee tee the credentials again if it failed to connect after so many tries
I want to move the code to an ESP32 and fix these issues. I need to have a solid, reliable connection with the WiFi.
A) possibly solve this disconnection issue possibly with a line of code for high power mode?
B) make a code that checks if it is still connects if not to reconnect t rather than send it back to the cridential page so basically solve the down time by some logic that will maintain the always connected situation.
C) I want to add a line of code to have an indicator light turn on if it can’t connect or loses connection and turns off when there is a connection.
Here is what I have so far for the main.cpp
#include <WiFiManager.h>
void setup() {
Serial.begin(115200);
Files.start();
Lights.begin();
UI.begin();
Auth.begin();
COM.begin();
Serial.print(F("\n\n====================<<<<<<<< WiFi Manager >>>>>>=====================\n\n"));
factoryTest();
Serial.println(FW_VERSION);
#ifdef COLORCODE
Lights.alertStatus = ALERT_BOOTUP;
Lights.alert();
#endif
WiFiManager wifiManager;
//wifiManager.setConfigPortalBlocking(false);
wifiManager.autoConnect("Goal Light");
//while (WiFi.status() != WL_CONNECTED) {
#ifdef COLORCODE
Lights.alertStatus = ALERT_WIFI;
if (wifiManager.getWiFiIsSaved()) {
Network.loop();
}
Lights.loop();
#endif
//wifiManager.process();
//}
Lights.alertStatus = ALERT_ERROR;
Lights.status = LIGHT_PAUSED;
Files.update();
if (Files.check("/user.txt") && Files.check("/password.txt")) {
Updater OTA;
}
Auth.authenticate();
UI.buildWeb();
}
int period = 1500;
unsigned long time_now = 0;
void loop() {
if (millis() - time_now > period) {
time_now = millis();
}
Sport.loop();
UI.wss->loop();
dnsServer.processNextRequest();
server.handleClient();
SB.loop();
Lights.loop();
#ifdef COLORCODE
Network.loop();
#endif
}
I have platformio that it was made on.
When I move it to my esp32 code I’m getting error for things Im not sure how to fix .

Related

How to send AT commands to ESP32 LilyGo-T-Call-SIM800?

I've been working with a LilyGo-TCall-SIM800 module for several days, trying to get out of a dead end.
I have tried an example from "random nerd tutorials" which works correctly. The module connects to the internet and can send data to the cloud.
I have the problem to send AT commands to the SIM800L chip integrated in the module. I can't get the chip to react back.
I have tried using Serial1 and Serial2. I have also tried configuring the RX and TX transmission pins, and I have tried with different baudrates. Always with negative results... when sending the "AT\r" command to the SIM800L, it should return "OK". But it never does.
I have simplified the code as much as possible to minimize errors:
/*
Name: TestAT.ino
Created: 08/12/2022 23:15:28
Author: user
*/
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMon Serial
// Comunications between ESP32 and SIM800L
#define SerialAT Serial1
//Comunications between ESP32 ans SIM800L go thought TX and RX pins on Serial1 Port
#define MODEM_RX1 16
#define MODEM_TX1 17
void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(1000);
//Set SerialAT baud rate
SerialAT.begin(38400, SERIAL_8N1, MODEM_RX1, MODEM_TX1);
//Set timeLimit for SerialAT reads
SerialAT.setTimeout(2000);
}
void loop() {
String returned = "";
char ATcommand[] = { 'A','T','\r' };
SerialAT.print(ATcommand);
delay(1000);
returned = SerialAT.readString();
SerialMon.print(millis());
SerialMon.print(" - ");
SerialMon.print(ATcommand);
SerialMon.print(" - SerialAT returned:");
SerialMon.println(returned);
}
Anybody can help me out on this? Any idea or sugestion?
Thanks in advance

How to add two physical buttons to AC fan dimmer sketch and update the corresponding slider/step widget once it’s pressed

There are a lot of AC Fan dimmer codes are available in internet with zero cross detection and runs by Blynk app as well.
Problem is All those are only controllable by wifi (with internet) , rather have no manual control (without internet) at all.
I share a code below for AC fan dimmer which is runs by blynk app (Board NodeMCU) . It is only runs when wifi is available, i.e it has no manual contro. I am trying to improve/modify the same code by adding two physical push buttons to control Fan speed manually when internet is not available. In this case I am unable to modify the codes for these two push buttons which also capable to increase and decrease the fan speed along with the Blynk app slider button. Can anyone help/Guide me to develop this.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define triacPulse 4 //D2
#define ZVC 12 //D6
int Slider_Value;
int dimming;
int x = 0;
char auth[] = "AUTH TOKEN"; // You should get Auth Token in the Blynk App.
char ssid[] = "SSID"; // Your WiFi credentials.
char pass[] = "PASS"; // Set password to "" for open networks.
BLYNK_WRITE(V1) // function to assign value to variable Slider_Value whenever slider changes position
{
Slider_Value = param.asInt(); // assigning incoming value from pin V1 to a variable
}
void setup()
{
pinMode(ZVC, INPUT_PULLUP);
//digitalWrite(2, INPUT_PULLUP); // pull up
pinMode(triacPulse, OUTPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
attachInterrupt(digitalPinToInterrupt(ZVC), acon, FALLING); // attach Interrupt at PIN2
}
void loop()
{
Blynk.run();
// When the switch is closed
dimming = map(Slider_Value, 0, 100, 7200, 200);
}
void acon()
{
// Serial.println("REad");
delayMicroseconds(dimming); // read AD0
digitalWrite(triacPulse, HIGH);
delayMicroseconds(50); //delay 50 uSec on output pulse to turn on triac
digitalWrite(triacPulse, LOW);
// Serial.println(digitalRead(triacPulse));
}

can't pair mac and arduino fio with bluetooth bee

I can't get my arduino fio with bluetooth bee paired with my mac. I got my application working with a different board (arduino uno) and USB connection. The code I'm uploading to my arduino fio is below:
#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3); // RX, TX
void setup() {
// bluetooth bee setup
softSerial.print("\r\n+STWMOD=0\r\n"); // set to slave
delay(1000);
softSerial.print("\r\n+STNA=MYAPP\r\n"); // set name
delay(1000);
// Serial.print("\r\n+STAUTO=1\r\n"); // permit auto-connect of paired devices
softSerial.print("\r\n+STOAUT=1\r\n");
delay(1000);
//Serial.print("\r\n +STPIN=0000\r\n"); // set PIN
//delay(1000);
softSerial.print("\r\n+STBD=9600\r\n"); // set baud
delay(2000); // required
// initiate BTBee connection
softSerial.print("\r\n+INQ=1\r\n");
delay(20000); // wait for pairing
// Start the software serial.
softSerial.begin(9600);
// Start the hardware serial.
Serial.begin(9600);
}
I think the pins are right -- 2 and 3 seem to be the pins that connect to the bluetooth bee. I've been googling for 2 days straight, and people don't seem to have problems pairing. What am I doing wrong?
Thanks,
Ok -- this took me nearly three solid days of Google-fu, and I stumbled across this page. Apparently that guy, also, had an immense amount of trouble finding a solution, so hopefully having the solution posted on StackOverflow will help future inquirers.
Really, two things are necessary. First, for whatever reason, I have no idea why, you don't worry about the "software serial". Just address the "Serial". Secondly, it will not work if you don't have the baud for the Serial at 38400. I'm actually using a "software serial" to talk to another device, and that baud is at 9600, but for the bluetooth Serial, you want it at 38400.
If you define "setup" as follows, the BluetoothBee should blink red and green, and pair (mac has nothing to do with it):
long DATARATE = 38400; // default data rate for BT Bee
char inChar = 0;
int LED = 13; // Pin 13 is connected to a LED on many Arduinos
void setup() {
Serial.begin(DATARATE);
// bluetooth bee setup
Serial.print("\r\n+STWMOD=0\r\n"); // set to slave
delay(1000);
Serial.print("\r\n+STNA=myDeviceName\r\n"); // set the device name
delay(1000);
Serial.print("\r\n+STAUTO=0\r\n"); // don't permit auto-connect
delay(1000);
Serial.print("\r\n+STOAUT=1\r\n"); // existing default
delay(1000);
Serial.print("\r\n +STPIN=0000\r\n"); // existing default
delay(2000); // required
// initiate BTBee connection
Serial.print("\r\n+INQ=1\r\n");
delay(2000); // wait for pairing
pinMode(LED, OUTPUT);
}
Then, after pairing you should see another serial port under 'tools -> serial port' in your Arduino IDE. If you select that and define the "loop" function as follows, you should be able to send those commands and get verification that you are, in fact, talking to the bluetooth bee:
void loop() {
// test app:
// wait for character,
// a returns message, h=led on, l=led off
if (Serial.available()) {
inChar = Serial.read();
if (inChar == 'a') {
Serial.print("connected"); // test return connection
}
if (inChar == 'h') {
digitalWrite(LED, HIGH); // on
}
if (inChar == 'l') {
digitalWrite(LED, LOW); // off
}
}
}

Arduinos IDE Serial Monitor works while XCode popen() does not.

I am trying to communicate with my Arduino through popen() function. I wrote a simple Mac App in XCode:
- (IBAction)ButtonPressed:(id)sender {
popen("echo hello world > /dev/tty.usbmodem1411", "r");
}
And here is the Arduino Code:
int redPin = 8;
int greenPin = 9;
int bluePin = 10;
int inByte = 0; // for incoming serial data
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(8000);
}
void loop()
{
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
Serial.print(inByte);
setColor(inByte,inByte,inByte);
delay(1000);
setColor(0,0,0);
}
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Now, when I try to use Arduino Serial Monitor and write some gibberish there my LED's light up fine and I see that it is working. When I run my XCode program, press the button, nothing happens. I did set break points and I did check that the line of code gets executed. I double checked the serial port, it is all fine, but no luck. It still does not work.
Basically I solved the problem by using IOKit/ioctl. I am still not sure why popen() did not work, might be because Arduino IDE was using the port and thus it was not available, however IOKit works like a charm. Plus it allows more control and flexibility, you can actually search for ports before you start and see if they are available. If anyone runs in to the same problem check http://playground.arduino.cc/Interfacing/Cocoa#IOKit. Thanks for all help.

Controlling Arduino-connected servos with the WiFly shield via an ad-hoc connection

I'm trying to control some servos connected to an Arduino (breadboarded) over an ad-hoc connection. I've set up the network, can telnet into the WiFly, and can even do some simple controls (for example, turning an LED on and off). However, when I try to start and stop a servo based on a character typed into the telnet session, the servo will run for half a second, then stop - after which the WiFly stops responding completely. My code for the LED works:
void loop(){
delay(100);
index = 0;
while(serialWiFly.available() > 0){
if(index < 100){
inputIn = serialWiFly.read();
input[index] = inputIn;
index++;
input[index] = '\0';
}
if(inputIn == 'a')
digitalWrite(13, HIGH);
if(inputIn == 'z')
digitalWrite(13, LOW);
} //end while
serialWiFly.flush();
delay(10);
} //end loop
This lets me turn the LED on by pressing 'a', and off by pressing 'z'. Cool. But when I add a moveForward() function:
void moveForward(){
myservo.write(124);
}
And call it from my loop:
if(inputIn == 'a') moveForward();
The servo will spin and then stop, as I've described. I'm at a loss here - how can I fix this problem?
If anyone stumbles across this, I still don't know what caused it, but I fixed it by using an Arduino MiniPro instead of my standalone breadboarded unit. I believe it might have something to do with pulling the 'reset' pin HIGH or LOW (which I neglected to do in my breadboarded version.)

Resources