Local Server - Slow / unresponsive

Hello everyone

Just recently got my local server running (thanks Gunner).

i left it run overnight, and seemed fine, but then when i started to interact with it, locked up, and since has been unresponsive, working intermittently, not at all sometimes, etc.

I am using server-0.36.0, java 10 and a Mega 2560 with USB Serial link. I have simplified my code (and re-ran it to ensure the problem still exists) as shown below.

That said, I do think it is something related with the server. The code (full version) seemed to work fine with blynk cloud - but switched to local for latency / internet dependability reasons.

The blynk logs don’t seem to tell much, I can provide anytime. I should ask though, would the “best place to look” be in the blynk / postgres / stats / worker files? stats seems to have the most in it, but I am not sure how to use it in this case?

Appreciate your time in advance, thanks!

Sn00ky


/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial1
#include <avr/wdt.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Countimer.h"
#include <SimpleTimer.h>
#include <BlynkSimpleStream.h>
#include <WidgetRTC.h>
#include "HX711.h"  //You must have this library in your arduino library folder

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
#define BLYNK_GREY      "#707172"
#define BLYNK_ORANGE    "#d88e04"
#define BLYNK_WHITE     "#ffffff"

#define relaypin1 24
#define relaypin2 26
#define relaypin3 28
#define relaypin4 30
#define relaypin5 32
#define relaypin6 34
#define relaypin7 36
#define relaypin8 38

#define alarmledpin 37
#define sonarpin 35

#define ONE_WIRE_BUS 22
#define TEMPERATURE_PRECISION 12

byte dssensorHLT[8] = { 0x28, 0xFF, 0x45, 0x8C, 0x88, 0x16, 0x3, 0x5B };  //2017-05-17 HLT
byte dssensorMLT[8] = { 0x28, 0xFF, 0x3F, 0x2D, 0x91, 0x16, 0x4, 0xEA };  //2017-05-31 MLT
byte dssensorILT[8] = { 0x28, 0xFF, 0x0E, 0x85, 0x90, 0x16, 0x5, 0xE3 };  //2017-05-31 Inline Sensor
byte dssensorRelay1[8] = { 0x28, 0xFF, 0xA1, 0x43, 0xA1, 0x16, 0x5, 0xFA };  //2017-05-21 Relay Sensor 1
byte dssensorRelay2[8] = { 0x28, 0xFF, 0x2D, 0x1E, 0xA1, 0x16, 0x4, 0x0B };  //2017-05-21 Relay Sensor 1

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//HLT Temperature
#define CLK 23
#define DIO 25

//MLT Temperature
#define CLK2 27
#define DIO2 29

//Inline Temperature
#define CLK3 31
#define DIO3 33

//Setup instances for each Display
TM1637Display displayHLT(CLK, DIO);
TM1637Display displayMLT(CLK2, DIO2);
TM1637Display displayILT(CLK3, DIO3);

//Blank display
uint8_t data[] = { 0x00, 0x00, 0x00, 0x00 };

//char auth[] = "*************************";  //BlynkCloud Token
//Blynk LOCAL Server Auth Code
char auth[] = "**********************************";  //Local Server 2018-05-02

BlynkTimer timer;

#define BlynkOutput  //turn on or off blynk virtual writes

WidgetLED ledfan1(V8);
WidgetLED ledfan2(V9);

//WidgetRTC blynkrtc;

BLYNK_CONNECTED()
{
  blynkrtc.begin();  //Blynk RTC Widget
  Blynk.syncAll();
}

unsigned long millisloop;
unsigned long last;

int fanontemp = 82;
int relayalarmtemp = 100;

double HLTTemp, HLTTempSet, MLTTemp, ILTTemp, Relay1Temp, Relay2Temp;
double HLTThreshold = 0.25;
String HLTStatus = "N/A";

double mashTime, boilTime, finingsTime, hop1Time, hop2Time, hop3Time, hop4Time;
int mashTimeON, boilTimeON;

int testvalue = 1;

void setup()
{

  blynksetup();
  //setupdisplays();
  //initializepins();
  setuptempsensors();

  timer.setInterval(790L, requestDSTemps);
  timer.setInterval(800L, receiveDSTemps);
  //timer.setInterval(1502L, Evaluate);
  //timer.setInterval(5001L, fancheck);
  //timer.setInterval(850L, blynkupdate1);
  //timer.setInterval(5000L, blynkupdate2);
  //timer.setInterval(10000L, timerupdate);
  timer.setInterval(1000L, test);

}



void loop()
{
  Blynk.run();
  timer.run();
  //looptimer();
}


void blynksetup()
{
  //Start Blynk USB Serial
  Serial.begin(9600);
  Blynk.begin(Serial, auth);
}

void setupdisplays()
{
  //Set display brightness
  displayHLT.setBrightness(0x0f);
  displayMLT.setBrightness(0x0f);
  displayILT.setBrightness(0x0f);
}

void setuptempsensors()
{
  //OneWire Dallas Temperature Library
  sensors.begin();
  sensors.setResolution(dssensorHLT, 12);
  sensors.setResolution(dssensorMLT, 12);
  sensors.setResolution(dssensorILT, 12);
  sensors.setResolution(dssensorRelay2, 12);
  sensors.setResolution(dssensorRelay2, 12);
}

void test()
{
  Blynk.virtualWrite(V14, testvalue);
  testvalue = testvalue + 1;
}


void requestDSTemps()
{
  sensors.requestTemperatures();
}


void receiveDSTemps()
{
  HLTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorHLT));
  MLTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorMLT));
  ILTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorILT));
  Relay1Temp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorRelay1));
  Relay2Temp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorRelay2));

  displayHLT.showNumberDec(HLTTemp);  //Serial1.print("HLT Temp: ");  Serial1.println(HLTTemp);
  displayMLT.showNumberDec(MLTTemp);  //Serial1.print("MLT Temp: ");  Serial1.println(MLTTemp);
  displayILT.showNumberDec(ILTTemp);  //Serial1.print("ILT Temp: ");  Serial1.println(ILTTemp);
}


As this is USB it is hard to predict where exactly the issue. I don’t think this is server issue, unless server eats 100% of CPU (also nobody reported something similar). Local network gives lower latency and packets go faster, that may cause issues with USB link, as it not well suited for those goals :).

Thanks for the quick response Dmitriy

I am wondering if perhaps I can slow things down then for this particular project, such that the USB link is feasible?

If so, how would I do that? I can slow my code writes / reads to say 10/second or so, easily, perhaps slower. How would I slow things down on the server side?

CPU seems to be running fine.

Thanks

I think all you need to do is just increase time interval in your timer and that’s will fix the issue. Just a guess, however, it is easy to check.

Doesn’t seem to change anything…
Is there somewhere in the logs I could look for clues?

I still use USB link for some projects… and before switching to WiFi I ran USB on my Mega… in fact it was quicker on USB then WiFi :stuck_out_tongue: requiring me to make timing adjustments for the added latency of WiFi… go figure… but then it is wired vs. wireless.

@Sn00ky What are you running your Local Server on? And did you try this exact sketch on the Cloud Server?

You might also want to stager the timers a bit more… is 10ms long enough between the request and receive functions? I don’t think so…

I don’t use multiple timers for my DS18B20 sensors (reading up to 5 of them), but it does have a 250ms delay between request and get commands… and using the delay is not an issue since I only call it every 10 minutes.

void getTempData()
{
  DS18B20.requestTemperatures();
  delay(250);

  Blynk.virtualWrite(V45, DS18B20.getTempCByIndex(0));
  Blynk.virtualWrite(V46, DS18B20.getTempCByIndex(1));
  Blynk.virtualWrite(V51, DS18B20.getTempCByIndex(2));
  Blynk.virtualWrite(V52, DS18B20.getTempCByIndex(3));
  Blynk.virtualWrite(V53, DS18B20.getTempCByIndex(4));
}

Hello again Gunner!

Local server is on a windows 7 PC workstation. CPU with my normal running is usually < 25% and RAM is usually about 50-70% of 8Gb (I use this computer for several things such as media server and data collection. I suspect it still has plenty to be able to run the local server, but perhaps I’m wrong?

I just recently changed my timers to be faster intentionally - more for ability than necessity I can admit. I do have the library changed for DS18B20 such that it doesn’t sit and wait the 750ms (12 bit). It works great on other projects, and this one prior to the move to local server. I certainly will change it, but at this time, I am having the problems without even calling the temperature requests (commenting it all out) - so perhaps not this issue? Again, all eyes for opposition!

Glad to hear USB is working for you - I am currently rebuilding my project again from Arduino_USB_Serial example, piece by piece to see how much it takes to find the problem…

And no, not the exact sketch posted on the cloud - but the full sketch it came from was - I then simplified it for troubleshooting and for posting - and the posted version does have the problem.

Plenty of power… Local Server will run on a lowly single core Raspberry Pi Zero W :slight_smile: Just not fully functional with Java10 (which is why I was asking)… still best to stick with Java8 for the RPis for now.

But PC based server should be just fine AFAIK… and I don’t see how having both the USB link and server on same PC could be an issue, but have never tried it myself (my LS is on an old Netbook running Linux Mint). I would suspect something in the code and or timers still.

One thing to test is another separate project and device (if you have one) doing something, anything, relatively simple like an UpTimer… then seeing if it also bogs down (meeting server issue) or seems to work just fine (meaning code issue).

And yes it is possible to run multiple USB links… I think I had three running for awhile, way back in my pre-ESP days :smiley:

Oh the ESP days - I am just trying to get started with those. Lots of fun there - and headaches…kinda on hold for the moment though.

I have another blynk project running a whole range of things, mainly coolers / fermenters - works great! There is some disconnect issues / but I haven’t taken the time to fully troubleshoot them yet. It runs on the cloud however. I could switch it to the local server as a test though, simply clone the app and change the connect (luckily it stays connected to the PC all the time since it always evolving…

I am really wondering if perhaps my app is just a mess - it has been built, and changed and tweaked - full of widgets and things, perhaps some that are not even working or looking for Blynk_Reads that don’t exist. As I rebuild my code further I am rebuilding the App too…

Good point… something to watch for is once you start using virtual pins, don’t mix PUSH and reading rates on your widgets… just stick with PUSH and relevant code. I once had strange issues when leaving reading rates unnecessarily set on many widgets.

Makes sense

I learned the hard way with my other project how reading rates can throw you into flooding issues, and from there learned more efficient ways of setting up the app…

I kept adding sections of code back, and finally found the first sign of problem.
The bottom of the code, has BLYNK_WRITE(V19). When this is commented out, code runs smooth, when I enable, code slows, hangs and stumbles. I have a 500ms write running to to help notice the delays, runs smooth and timely when the BLYNK_WRITE is disabled for V19.
I write using a slider widget, send on release “on”, scaled from 149 to 185. 149 signifies to arduino to turn off.
Any ideas?

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial1
#include <avr/wdt.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Countimer.h"
#include <SimpleTimer.h>
#include <BlynkSimpleStream.h>
#include <WidgetRTC.h>
#include "HX711.h"  //You must have this library in your arduino library folder
#include <BlynkSimpleStream.h>

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
#define BLYNK_GREY      "#707172"
#define BLYNK_ORANGE    "#d88e04"
#define BLYNK_WHITE     "#ffffff"

#define relaypin1 24
#define relaypin2 26
#define relaypin3 28
#define relaypin4 30
#define relaypin5 32
#define relaypin6 34
#define relaypin7 36
#define relaypin8 38

#define alarmledpin 37
#define sonarpin 35

#define ONE_WIRE_BUS 22
#define TEMPERATURE_PRECISION 12

byte dssensorHLT[8] = { 0x28, 0xFF, 0x45, 0x8C, 0x88, 0x16, 0x3, 0x5B };  //2017-05-17 HLT
byte dssensorMLT[8] = { 0x28, 0xFF, 0x3F, 0x2D, 0x91, 0x16, 0x4, 0xEA };  //2017-05-31 MLT
byte dssensorILT[8] = { 0x28, 0xFF, 0x0E, 0x85, 0x90, 0x16, 0x5, 0xE3 };  //2017-05-31 Inline Sensor
byte dssensorRelay1[8] = { 0x28, 0xFF, 0xA1, 0x43, 0xA1, 0x16, 0x5, 0xFA };  //2017-05-21 Relay Sensor 1
byte dssensorRelay2[8] = { 0x28, 0xFF, 0x2D, 0x1E, 0xA1, 0x16, 0x4, 0x0B };  //2017-05-21 Relay Sensor 1

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

BlynkTimer timer;

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

#define BlynkOutput  //turn on or off blynk virtual writes

WidgetLED ledHeartBeat(V7);
WidgetLED ledfan1(V8);
WidgetLED ledfan2(V9);

//WidgetRTC blynkrtc;

BLYNK_CONNECTED()
{
  //blynkrtc.begin();  //Blynk RTC Widget
  Blynk.syncAll();
}
int fanontemp = 82;
int relayalarmtemp = 100;

double HLTTemp, HLTTempSet, MLTTemp, ILTTemp, Relay1Temp, Relay2Temp;
double HLTThreshold = 0.25;
String HLTStatus = "N/A";

double mashTime, boilTime, finingsTime, hop1Time, hop2Time, hop3Time, hop4Time;
int mashTimeON, boilTimeON;

long appopentime = 1;
long loop2 = 1;
byte HBStatus = 0;

void setup()
{
  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  //blynksetup();
  //setupdisplays();
  //initializepins();
  setuptempsensors();

  timer.setInterval(500, rapidcount);
  timer.setInterval(400L, requestDSTemps);
  timer.setInterval(480L, receiveDSTemps);
  //timer.setInterval(1502L, Evaluate);
  //timer.setInterval(5001L, fancheck);
  timer.setInterval(500L, blynkupdate1);
  timer.setInterval(5000L, blynkupdate2);
  //timer.setInterval(10000L, timerupdate);
  
}

void rapidcount()
{
  loop2 = loop2 + 1;
  Blynk.virtualWrite(V0, loop2);
  if (HBStatus == 1)
  {
    ledHeartBeat.off();
    HBStatus = 0;
  }
  else
  {
    ledHeartBeat.on();
    HBStatus = 1;
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}


void setuptempsensors()
{
  //OneWire Dallas Temperature Library
  sensors.begin();
  sensors.setResolution(dssensorHLT, 11);
  sensors.setResolution(dssensorMLT, 11);
  sensors.setResolution(dssensorILT, 11);
  sensors.setResolution(dssensorRelay2, 11);
  sensors.setResolution(dssensorRelay2, 11);
}

void initializepins()
{
  pinMode(relaypin1, OUTPUT);
  pinMode(relaypin2, OUTPUT);
  pinMode(relaypin3, OUTPUT);
  pinMode(relaypin4, OUTPUT);
  pinMode(relaypin5, OUTPUT);
  pinMode(relaypin6, OUTPUT);
  pinMode(relaypin7, OUTPUT);
  pinMode(relaypin8, OUTPUT);
  pinMode(sonarpin, OUTPUT);
  digitalWrite(relaypin1, HIGH);
  digitalWrite(relaypin2, HIGH);
  digitalWrite(relaypin3, HIGH);
  digitalWrite(relaypin4, HIGH);
  digitalWrite(relaypin5, HIGH);
  digitalWrite(relaypin6, HIGH);
  digitalWrite(relaypin7, HIGH);
  digitalWrite(relaypin8, HIGH);
  digitalWrite(sonarpin, LOW);
}


void requestDSTemps()
{
  sensors.requestTemperatures();
}


void receiveDSTemps()
{
  HLTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorHLT));
  MLTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorMLT));
  ILTTemp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorILT));
  Relay1Temp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorRelay1));
  Relay2Temp = DallasTemperature::toFahrenheit(sensors.getTempC(dssensorRelay2));

//  displayHLT.showNumberDec(HLTTemp);  //Serial1.print("HLT Temp: ");  Serial1.println(HLTTemp);
//  displayMLT.showNumberDec(MLTTemp);  //Serial1.print("MLT Temp: ");  Serial1.println(MLTTemp);
//  displayILT.showNumberDec(ILTTemp);  //Serial1.print("ILT Temp: ");  Serial1.println(ILTTemp);
}

void blynkupdate1()
{
  #ifdef BlynkOutput
    if (Blynk.connected())
    {
      Blynk.virtualWrite(V11, HLTTemp);
      Blynk.virtualWrite(V12, HLTTempSet);
      Blynk.virtualWrite(V13, MLTTemp);
      Blynk.virtualWrite(V14, ILTTemp);
    }
  #endif
}

void blynkupdate2()
{
  #ifdef BlynkOutput
    if (Blynk.connected())
    {
      Blynk.virtualWrite(V5, Relay1Temp);
      Blynk.virtualWrite(V6, Relay2Temp);
      Blynk.virtualWrite(V1, HLTTemp);
      Blynk.virtualWrite(V2, HLTTempSet);
      Blynk.virtualWrite(V3, MLTTemp);
      Blynk.virtualWrite(V4, ILTTemp);
    }
  #endif
}


//BLYNK_WRITE(V19)
//{
//  double d = param.asDouble();
//  if (d == 149)
//  {
//    HLTTempSet = 0;
//  }
//  else
//  {
//    HLTTempSet = d;
//  }
//  Blynk.virtualWrite(V12, HLTTempSet);
//}

Seems I have been somewhat successful with rebuilding the app. Been a while but I have it up and running pretty stable now. I don’t have all of my functions enabled yet , but things are looking good so far.

Thanks for the help!