Wifi Continuously Connect and Reconnect on mobile device

Thank you for your help.
Is there an updated guide on how to connect to the local server on a windows device?

or is this not what I want?

I wish :laughing:
I removed the lcd and the wire libraries. The problem still happens when I open the app. I might try another app besides Blynk :pensive: .

Hello,
I have removed the LCD screen completely, changed some values in the library, tried new firmware but I cannot keep wifi connection with the Blynk app. I have the serial monitor open when the code is running, and I only get “packet too big” when the app is pulled up. Otherwise the code runs smoothly for hours, but as soon as I open the app I get the packet message.
Is it possible to clear the packet when it reaches a certain limit without restarting the arduino?
Like once the data is pushed the packet can be cleared?
Thank you!

Packet too big is an internal message that means “something went wrong”, probably caused by bad coding.
Post your full current code and any additional details that will be of help.

Pete.

There are a couple of components to this code. There are voltage and temp readings and a motor control.

//#define BLYNK_DEBUG // Opt
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG    
#define BLYNK_NO_BUILTIN 
//#define BLYNK_NO_FLOAT 
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SPI.h>
#include <AFMotor.h>
#include <max6675.h>
#include "Adafruit_MAX31855.h"
#include <Keypad.h>


//Assign volt values to some number to start with
float volt1 = 2;
float volt2 = 3;
float volt3 = 4;
float volt4 = 5;
float volt5 = 8;
float volt6 = 9;
float volt7 = 10;
float volt8 = 11;
int maxValue = 3; // current sensor value that will trigger slowdown
int safeValue = 100; //safe motor speed

//Thermocouple Section
#define MAXDO1   23
#define MAXCS1   25
#define MAXCLK1  27
#define MAXDO2   48
#define MAXCS2   50
#define MAXCLK2  52
#define MAXDO3   41
#define MAXCS3   39
#define MAXCLK3  37
#define MAXDO4   47
#define MAXCS4   49
#define MAXCLK4  51

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple2(MAXCLK2, MAXCS2, MAXDO2);
MAX6675 thermocouple4(MAXCLK4, MAXCS4, MAXDO4);
MAX6675 thermocouple3(MAXCLK3, MAXCS3, MAXDO3);
MAX6675 thermocouple1(MAXCLK1, MAXCS1, MAXDO1);

//LED
WidgetLED led1(V45);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
//Location of RX and TX pins on Arduino board
#define EspSerial Serial3

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

//Identify location of motor on shield
AF_DCMotor motor(2);

//Keypad Code..Use when there is no Internet
const byte ROWS = 4; 
const byte COLS = 3; 

char hexaKeys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {36, 34, 32, 30}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 26, 24};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 


int x = 0;

BlynkTimer timer;

//Below are functions they start with vois but are not the main void loop or void setup

void setup()
{
  // Debug console
  Serial.begin(115200);
  EspSerial.begin(ESP8266_BAUD);
  delay(2000);

  Blynk.begin(auth, wifi, ssid, pass);
  Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8080);
 // Blynk.connectWiFi(ssid, pass);
  //Blynk.begin(auth, wifi, ssid, pass, LOCAL_SERVER, 8080);
  timer.setInterval(1000L, myTimerEvent);
  timer.setInterval(3000L, getTemp);
  timer.setInterval(3000L, getVolt);
//  timer.setInterval(3000L, keyPad);

motor.run(RELEASE);
  //motor.run(FORWARD);
}



void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V60, millis() / 1000);//Assign the virtual pin(60) to the timer

}

void getVolt()
{
  //assign the volt readings to an anologue pin 
  //volt1
volt1 = analogRead(A1);//Read the value of the potentiometer to val
  volt1 = volt1/1024*5.0;// Convert the data to the corresponding voltage value in a math way
  
///volt2
    volt2 = analogRead(A2);//Read the value of the potentiometer to val
    volt2 = volt2/1024*5.0;// Convert the data to the corresponding voltage value in a math way

//volt3
   volt3 = analogRead(A3);//Read the value of the potentiometer to val
  volt3 = volt3/1024*5.0;// Convert the data to the corresponding voltage value in a math way

   volt4 = analogRead(A4);//Read the value of the potentiometer to val
  volt4 = volt4/1024*5.0;// Convert the data to the corresponding voltage value in a math way
   
 //volt in arduino section
 volt5 = analogRead(A5);//Read the value of the potentiometer to val
  volt5 = volt5/1024*5.0;// Convert the data to the corresponding voltage value in a math way
  
///volt6
    volt6 = analogRead(A8);//Read the value of the potentiometer to val
    volt6 = volt6/1024*5.0;// Convert the data to the corresponding voltage value in a math way

//volt7
   volt7 = analogRead(A9);//Read the value of the potentiometer to val
  volt7 = volt7/1024*5.0;// Convert the data to the corresponding voltage value in a math way

   volt8 = analogRead(A10);//Read the value of the potentiometer to val
  volt8 = volt8/1024*5.0;// Convert the data to the corresponding voltage value in a math way
  
if (volt1 >= maxValue)
   {   
    motor.run(FORWARD);
   motor.setSpeed(safeValue); 
   led1.on();
    Serial.println("LED on V1: red"); 
    Blynk.virtualWrite(V20, safeValue);
   }
   if (volt1 <= maxValue)
   {   
   led1.off();
    Serial.println("LED on V1: off"); 
   }
//   if (volt1 <= maxValue)
//   {   
//   motor.setSpeed(pinValue); 
//   }
//Assign each voltage reading to its own virtual pin
Blynk.virtualWrite(V1, volt1);
Blynk.virtualWrite(V2, volt2);
Blynk.virtualWrite(V3, volt3);
Blynk.virtualWrite(V4, volt4);
Blynk.virtualWrite(V5, volt5);
Blynk.virtualWrite(V6, volt6);
Blynk.virtualWrite(V7, volt7);
Blynk.virtualWrite(V8, volt8);
    


}

void getTemp()
{
 // Assign a variable to the farenheit conversions of the digital pins
   double t1 = thermocouple1.readFarenheit();

   double t2 = thermocouple2.readFarenheit();
   
   double t3 = thermocouple3.readFarenheit();
  
   double t4 = thermocouple4.readFarenheit();
  

   //Display these values in the Serial monitor(top right looking glass symbol)
     Serial.print("Thermocouple Temp1 = *");
     Serial.println(t1);
     Serial.print("Thermocouple Temp2= *");
     Serial.println(t2);
     Serial.print("Thermocouple Temp3 = *");
     Serial.println(t3);
     Serial.print("Thermocouple Temp4= *");
     Serial.println(t4);

     //Assign each temp reading to its own virtual pin on Blynk app
    Blynk.virtualWrite(V10, t1);
    Blynk.virtualWrite(V11, t2); 
    Blynk.virtualWrite(V12, t3);
    Blynk.virtualWrite(V13, t4); 

}

BLYNK_WRITE(V20)
{
  //Connect a virtual pin to the motor to control its speed
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  //Tell motor to run in one direction, forward
   if (volt1 <= maxValue)
   {   
 volt1 = analogRead(A1);//Read the value of the potentiometer to val
  volt1 = volt1/1024*5.0;//
  motor.run(FORWARD);
  Serial.println(pinValue);
  motor.setSpeed(pinValue);    
   }
//while (V1 > 2)
//{
//  int pinValue = param.asInt();
//  int pinValue2= pinValue/2;
//  motor.run(FORWARD);
//  Serial.println("pinValue2=");
//  Serial.println(pinValue2);
//  motor.setSpeed(pinValue2);
//}
//}

}
BLYNK_APP_DISCONNECTED() {
// Your code here

//void keyPad()
//{
   char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
motor.run(FORWARD);
if (customKey == '0')
{
  motor.setSpeed(0);
}
if (customKey == '1')
{
  motor.setSpeed(28);
}
if (customKey == '2')
{
  motor.setSpeed(57);
}
if (customKey == '3')
{
  motor.setSpeed(85);
}
if (customKey == '4')
{
  motor.setSpeed(113);
}
if (customKey == '5')
{
  motor.setSpeed(142);
}
if (customKey == '6')
{
  motor.setSpeed(170);
}
if (customKey == '7')
{
  motor.setSpeed(198);
}
if (customKey == '8')
{
  motor.setSpeed(227);
}
if (customKey == '9')
{
  motor.setSpeed(255);
}




}
}

void loop()
{
  //Keep loop clean
  //run blynk app and timer
 Blynk.run();
 timer.run(); // Initiates BlynkTimer
}


You can try to use the Blynk_Teensy library, you can use for Mega2560 just to see if the issue fixed (as similar issue happened to Teensy 4.0)

Then just replace in the code

//#include <BlynkSimpleShieldEsp8266.h>
#include <BlynkSimpleShieldEsp8266_Teensy.h>

There are also some typo errors in the call, not readFarenheit(), but readFahrenheit().

Must be:

 double t1 = thermocouple1.readFahrenheit();

  double t2 = thermocouple2.readFahrenheit();

  double t3 = thermocouple3.readFahrenheit();

  double t4 = thermocouple4.readFahrenheit();

Then post the results.

1 Like

A few suggestions…

Try lowering your ESP8266_BAUD rate to 9600. This will require you to set the ESP-01 to work at that lower baud rate using an AT command as well as changing the above line of code.

Your void getVolt() function does quite a lot of work - 8x analogue reads, 8 x floating point maths, 10x Blynk virtual writes (the led1.on / off commands are also virtual writes) and a couple if if statements to be evaluated. Try cutting this down so that you only do half of the work and see if this helps.

The void getTemp() function is also very similar in what it does - try the same thing with this one.

In addition, you’re also calling these two functions at exactly the same time (every 3 seconds). Your single core processor can’t do these simultaneously, so they are queued one after the other. It’s better to set them up on timer cycles that don’t clash in this way.

Could you explain the logic behind the use of the BLYNK_APP_DISCONNECTED() function?
Is it really intended to allow the keypad to be used when the app on your phone(s) isn’t connected to the Blynk server, or is it meant to be there to allow manual control when your Arduino to internet connection is down?
If it’s the latter then you’re using the wrong function.

Pete.

I get this error
class Adafruit_MAX31855' has no member named 'readFahrenheit

I don’t know which library you installed. Try the genuine Adafruit MAX31855 from Arduino Library Manager. The function prototype must be

double readFahrenheit(void);

not the one with wrong name typo-error

/*!
 * @file Adafruit_MAX31855.h
 *
 * This is the documentation for Adafruit's MAX31855 thermocouple breakout
 * driver for the Arduino platform.  It is designed specifically to work with
 * the Adafruit MAX31855 breakout: https://www.adafruit.com/products/269
 *
 * These sensors use SPI to communicate, 3 pins are required
 * to interface with the breakout.
 *
 * Adafruit invests time and resources providing this open source code,
 * please support Adafruit and open-source hardware by purchasing
 * products from Adafruit!
 *
 * Written by Limor Fried/Ladyada for Adafruit Industries.
 *
 * BSD license, all text above must be included in any redistribution.
 *
 */

#ifndef ADAFRUIT_MAX31855_H
#define ADAFRUIT_MAX31855_H

#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Adafruit_SPIDevice.h>

/**************************************************************************/
/*!
    @brief  Sensor driver for the Adafruit MAX31855 thermocouple breakout.
*/
/**************************************************************************/
class Adafruit_MAX31855 {
public:
  Adafruit_MAX31855(int8_t _sclk, int8_t _cs, int8_t _miso);
  Adafruit_MAX31855(int8_t _cs);

  void begin(void);
  double readInternal(void);
  double readCelsius(void);
  double readFahrenheit(void);
  uint8_t readError();

private:
  Adafruit_SPIDevice spi_dev = NULL;
  boolean initialized;

  uint32_t spiread32(void);
};

#endif


1 Like

I have a keyboard in place just in case the wifi connection cuts out with the Blynk app. I was hoping that when the Blynk app was disconnected the keyboard function would turn on to control the speed of the motor.
The actual wifi seems fine, but I am having trouble with keeping the Blynk app connected.

Your Arduino doesn’t talk directly to the app, it talks to the server, and the app talks to the server too.

The BLYNK_APP_DISCONNECTED callback I s triggered when there is no device running the app connected to the server (bear in mind that you can have multiple phones and tablets running the same app project).

If your Arduino isn’t connected to the server then it will never know whether or not the app is connected to the server, so using this callback is the wrong approach.

If you want to know if the Arduino is connected to the server then you need to call the Blynk.connected command.

Whether this will have the desired effect when you’re using the blocking Blynk.begin command is questionable. By the way, you have two Blynk.begin commands in your code. You should only have one.

Pete.

1 Like

I suggest that you use a simpler and more robust design such as

  1. Permit both KBD and APP to control the motor
  2. KBD, when detecting some key sequence, can set a flag to disable APP control, so that KBD can have total control of the motor. Local control must have higher priority than remote control.
  3. APP can control only when enabled by KBD (by previous flag). Certainly when APP is disconnected, you don’t need to know and care.

You also have to recheck your code, there are still too many possible problems in the code you can check and change as suggested by @PeteKnight , such as double Blynk.begin() calls, timer Interval too short and too close together, etc… Only you can have insight, means, time and energy to help yourself fixing the above-mentioned issues.

1 Like

Thank you, I guess I just needed new sets of eyes on the code.

Thank you, I’ll change up some things.