Déconnection problem arduino + sim 800l "interference in the program"

• Hardware model = arduino with sim 800l + 2 capteur : asc712 and zmpt101b
• Android version:2.27.34
• local server

i can’t stay connected and I can’t control the actuators What makes interference in the programming between the sensors code and Blynk code
Capture

#define BLYNK_TEMPLATE_ID           "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME           "Device"
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 60
#include <BlynkSimpleSIM800.h>
#include <TinyGsmClient.h>
#include "ACS712.h"
#include "EmonLib.h"
#include <Filters.h>
#define vCalibration 106.8
#define currCalibration 0.52

EnergyMonitor emon;


char auth[] = "N46Z45yasSLc-tw3EgfgTlKiY18b*****";

char apn[]  = "YourAPN";
char user[] = "";
char pass[] = "";
char server[] = "197.***.**.**";
int port = 8080;

const int sensorIn = A2;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

float testFrequency = 50;
float windowLength = 100 / testFrequency;

int RawValue = 0;
float Volts_TRMS;

float intercept = 0;
float slope = 1;

unsigned long printPeriod = 1000; //Measuring frequency, every 1s, can be changed
unsigned long previousMillis = 0;

RunningStatistics inputStats;

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(5, 4); // RX, TX
TinyGsm modem(SerialAT);


BlynkTimer timer;
float kWh = 0;
unsigned long lastmillis = millis();
WidgetTerminal terminal(V4);
void myTimerEvent()

{
  emon.calcVI(20, 2000);
  /*Serial.print("Vrms: ");
  Serial.print(emon.Vrms, A6);
  Serial.print("V");*/
  Blynk.virtualWrite(V0, emon.Vrms);
  /*Serial.print("\tIrms: ");
  Serial.print(emon.Irms, A2);
  Serial.print("A");*/
  Blynk.virtualWrite(V1, emon.Irms);
  /*Serial.print("\tPower: ");
  Serial.print(emon.apparentPower, 4);
  Serial.print("W");*/
  Blynk.virtualWrite(V2, emon.apparentPower);
  //Serial.print("\tkWh: ");
  kWh = kWh + emon.apparentPower * (millis() - lastmillis) / 3600000000.0;
  /*Serial.print(kWh, 4);
  Serial.println("kWh");*/
  Blynk.virtualWrite(V3, kWh);
  
  lastmillis = millis();
  
  Blynk.virtualWrite(V12, digitalRead(2));
  Blynk.virtualWrite(V13, digitalRead(3));
  Blynk.virtualWrite(V14, analogRead(A2));
  Blynk.virtualWrite(V15, analogRead(A6));

  //ignoring the value below 0.09
  Voltage = getVPP();
  VRMS = (Voltage / 2.0) * 0.707;
  AmpsRMS = (VRMS * 1000) / mVperAmp;
  Blynk.virtualWrite(V14, 0.9 * AmpsRMS * 110);  // To Gauge Widget @ .9pf and 110vac
  terminal.print(AmpsRMS);  // To Terminal Widget
  terminal.print(" Amps - ");

  terminal.flush();
}
float getVPP() {
  float result;
  int readValue;  //value read from the sensor
  int maxValue = 0;  // store max value here
  int minValue = 1023;  // store min value here
  uint32_t start_time = millis();
  while ((millis() - start_time) < 1500) {  // sample for 1 Sec
    readValue = analogRead(sensorIn);  // see if you have a new maxValue
    if (readValue > maxValue) {
      maxValue = readValue;  // record the maximum sensor value
    }
    if (readValue < minValue) {
      minValue = readValue;  // record the minimum sensor value
    }
  }
  // Subtract min from max
  result = ((maxValue - minValue) * 5.0) / 1023.0;
  return result;
}
void ac_read() {
  int rVal = 0;
  int sampleDuration = 100;  // 100ms
  int sampleCount = 0;
  unsigned long rSquaredSum = 0;
  int rZero = 511;   // For illustrative purposes only - should be measured to calibrate sensor.
  uint32_t startTime = millis();  // take samples for 100ms
  while ((millis() - startTime) < sampleDuration) {
    rVal = analogRead(A2) - rZero;
    rSquaredSum += rVal * rVal;
    sampleCount++;
  }
  double voltRMS = 5.0 * sqrt(rSquaredSum / sampleCount) / 1024.0;
  // x 1000 to convert volts to millivolts
  // divide by the number of millivolts per amp to determine amps measured
  // the 20A module 100 mv/A (so in this case ampsRMS = 10 * voltRMS
  double ampsRMS = voltRMS * 6.6;
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);//115200
  delay(3000);

  Serial.println("Initializing modem...");
  modem.restart();

  inputStats.setWindowSecs( windowLength );

  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(A0, OUTPUT);

  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(A2, INPUT);
  pinMode(A6, INPUT);

  emon.voltage(35, vCalibration, 1.7); // Voltage: input pin, calibration, phase_shift
  emon.current(34, currCalibration); // Current: input pin, calibration.

  Blynk.begin(auth, modem, apn, user, pass, server, port);
  timer.setInterval(9000L, myTimerEvent);

  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(12, LOW);

  digitalWrite(A0, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(13, LOW);
}
void loop()
{
  Blynk.run();
  timer.run();
}

Capture

Why do you have these lines in your sketch if you are using Blynk Legacy running on a local server?
What Blynk library version are you using?

Most of your ping times are very high - almost 6 seconds - which is usually a sign of a very poor GPRS signal and is most likely what is causing the disconnections, but its difficult to say without some meaningful debug messages.

When you post serial data to the forum please post it as text rather than a screenshot, and post it between triple backticks in the same way as when you post code. Also, the triple backticks need to be on a line of their own for them to work correctly.

Pete.

Hi Pete

i’m using blynk for chinese 0.5.9 version

i forgot to delete it

okay i’ll do that next time

i don’t think i have a poor GPRS signal , i have some project in the same place have very good GPRS signal.
do you think the problem in the library version?

This isn’t an official Blynk library version. You should use 0.6.1

I doubt it, the problem looks like the ping times.

Pete.

hi pete
i’m using the right library now and i’m in a good place having a good GPRS signal and have the same problem with the previous program, i think the problem in senser library because when i delete sensor program i have a good connection and request like this

Initializing modem...
[10034] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.5.8 on Arduino Nano

[10042] Modem init...
[10249] Connecting to network...
[18774] Network: Nedjma
[18775] Connecting to YourAPN ...
[25595] Connected to GPRS
[25668] Connecting to 197.***.**.**:8080
[26703] Ready (ping: 417ms).


#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 60
#include <BlynkSimpleSIM800.h>
#include <TinyGsmClient.h>
#include <Filters.h>
#define vCalibration 106.8
#define currCalibration 0.52



char auth[] = "N46Z45yasSLc-tw3EgfgTlKiY18b****";

char apn[]  = "YourAPN";
char user[] = "";
char pass[] = "";
char server[] = "197.140.16.54";
int port = 8080;


#include <SoftwareSerial.h>
SoftwareSerial SerialAT(5, 4); // RX, TX
TinyGsm modem(SerialAT);


void setup()
{
  // Debug console
  Serial.begin(115200);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);//115200
  delay(3000);

  Serial.println("Initializing modem...");
  modem.restart();

//  inputStats.setWindowSecs( windowLength );

  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(A0, OUTPUT);

  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(A2, INPUT);
  pinMode(A6, INPUT);

  Blynk.begin(auth, modem, apn, user, pass, server, port);

  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(12, LOW);

  digitalWrite(A0, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(13, LOW);
}
void loop()
{
  Blynk.run();
}

No, you aren’t….

Pete.

sorry i have send the previous data

11:24:17.172 -> [11165] 
11:24:17.172 ->     ___  __          __
11:24:17.172 ->    / _ )/ /_ _____  / /__
11:24:17.172 ->   / _  / / // / _ \/  '_/
11:24:17.172 ->  /____/_/\_, /_//_/_/\_\
11:24:17.172 ->         /___/ v0.6.0 on Arduino Nano
11:24:17.172 -> 
11:24:17.172 -> [11173] Modem init...
11:24:17.363 -> [11387] Connecting to network...
11:24:24.731 -> [18746] Network: Nedjma
11:24:24.731 -> [18747] Connecting to YourAPN ...
11:24:31.437 -> [25430] Connected to GPRS
11:24:31.531 -> [25502] Connecting to 197.*** .**.**:8080
11:24:32.915 -> [26890] Ready (ping: 582ms).

I’m guessing that you have multiple Blynk libraries installed if the compiler is picking-up tge 0.6.0 library instead of the 0.6.1 library that your screenshot sows.

Maybe time to have a manual clear out in your Arduino Libraries folder?

Pete.

the same problem -_-
i have delete all blynk libraries , i have now only the official one

13:03:58.959 -> Initializing modem...
13:04:07.146 -> [11195] 
13:04:07.146 ->     ___  __          __
13:04:07.146 ->    / _ )/ /_ _____  / /__
13:04:07.146 ->   / _  / / // / _ \/  '_/
13:04:07.146 ->  /____/_/\_, /_//_/_/\_\
13:04:07.146 ->         /___/ v0.6.1 on Arduino Nano
13:04:07.146 -> 
13:04:07.146 -> [11203] Modem init...
13:04:07.380 -> [11416] Connecting to network...
13:04:12.985 -> [17043] Network: Nedjma
13:04:12.985 -> [17044] Connecting to YourAPN ...
13:04:19.688 -> [23703] Connected to GPRS
13:08:39.002 -> [28418] Connecting to 197.140.16.54:8080
13:09:10.924 -> [60290] Ready (ping: 31172ms).
13:09:16.161 -> [65497] Connecting to 197.140.16.54:8080
13:09:17.921 -> [67279] Ready (ping: 590ms).
13:10:29.364 -> [138635] Connecting to 197.140.16.54:8080
13:10:36.406 -> [145682] Ready (ping: 5851ms).
13:11:48.557 -> [217711] Connecting to 197.140.16.54:8080
13:11:56.882 -> [226039] Ready (ping: 7147ms).

I’d suggest that you look at fixing the ping time. As I said before, it’s almost certainly whats causing the issue and is usually caused by a poor GPRS signal.

Pete.

when i remove sensor program the ping time get a great result

like this and he still connected always , the problem when i add the sensor program

Your ping times fluctuate wildly, from 590ms one minute to 5851ms the next. This is an indication of an issue, usually caused by signal strength.

and that’s most likely caused by the way that you’ve implemented the sensor code. I see while commands in there, which I always try to avoid where possible, and some rather odd programming methods. But, no matter how good your sketch is, if your Blynk connection is poor then you’ll get disconnections.

Pete.

hi pete
i get my while command from here ,from @Gunner program

As I said, I try to avoid them wherever possible when using Blynk.

Pete.

1 Like

thanks pete i will try to avoid it too

@Gunner can you give me a hand ?

Sadly, @Gunner doesn’t visit the forum very often now.
I think he moved away from Blynk when the IoT version was released.

Pete.

1 Like