Getting Nextion HTTP OTA uploads working

I created my own functions for Nextion, so I just need to call them and pass arguments

///////////////////////////////////// WriteStr /////////////////////////////////////
void WriteStr(String command, String txt) {
  String _component = command;
  String _strVal = txt;
  if (_strVal == "cmd") {
    Serial.print(_component); // for editor serial port simulation mode
    Serial.print("\xFF\xFF\xFF");

    Nextion.print(_component); // for Nextion serial port
    Nextion.print("\xFF\xFF\xFF");

  } else if (_strVal != "cmd") {
    Serial.print(_component);
    Serial.print("=\"");
    Serial.print(_strVal);
    Serial.print("\"");
    Serial.print("\xFF\xFF\xFF");

    Nextion.print(_component);
    Nextion.print("=\"");
    Nextion.print(_strVal);
    Nextion.print("\"");
    Nextion.print("\xFF\xFF\xFF");
  }
}

///////////////////////////////////// WriteNum /////////////////////////////////////
void WriteNum(String command, int val) {
  String _component = command;
  int _numVal = val;
  Serial.print(_component);
  Serial.print("=");
  Serial.print(_numVal);
  Serial.print("\xFF\xFF\xFF");

  Nextion.print(_component);
  Nextion.print("=");
  Nextion.print(_numVal);
  Nextion.print("\xFF\xFF\xFF");
}
///////////////////////////////////// WriteVis /////////////////////////////////////
void WriteVis(String command, int val) {
  String _component = "vis " + command;
  int _numVal = val;
  Serial.print(_component);
  Serial.print(",");
  Serial.print(_numVal);
  Serial.print("\xFF\xFF\xFF");

  Nextion.print(_component);
  Nextion.print(",");
  Nextion.print(_numVal);
  Nextion.print("\xFF\xFF\xFF");
}

///////////////////////////////////// readStr /////////////////////////////////////
void readStr(String TextComponent) {
  String _Textcomp = TextComponent;
  Serial.print("get ");
  Serial.print(_Textcomp);             // The String of a component you want to read on Nextion
  Serial.print("\xFF\xFF\xFF");
  NexListen();
  DataReceived();
}

void setup() {
Nextion.begin(NxBaud);
Serial.begin(SrlBaud);

For example :

  ///////////////////////////////////// temp interieure /////////////////////////////////////
  String T_Int = String(temperature).substring(0, 2);
  WriteStr( "home.T_Int.txt", T_Int);
1 Like

Oh boy! All those sketches that worked yesterday donā€™t work now :frowning: All say canā€™t get baud rateā€¦ the baud rate on the display says 250000 and the sketch is 250000 :no_good_man:

1 Like

That can help :

1 Like

Ok Iā€™ll see if I can implement this. Would a serial.read just before help to empty the buffer?

1 Like

Yes the serial read clean the buffer .

So today it is working again but only at 115200 baud rate.

1 Like

Hey Alexis, just a question. What do these two two functions look like or do?

1 Like

Itā€™s my script to read and decode the data received from Nextion

void NexListen() {
  delay(30);
  WriteVis( "47", 1); //ACK nextion widget
  if (Serial.available()) {
    Blynk.virtualWrite(V16, 255); // data led
    terminal.println("NexListen : " + Time);
    terminal.flush();

    while (Serial.available()) {
      incomingByte = Serial.read();
      data_from_nextion += char(incomingByte);
      x++;
      Blynk.run();
    }

    if (data_from_nextion.endsWith(endChar)) {
      x = 0;
      Blynk.virtualWrite(V16, 0); // data led
    }
  }
 WriteVis( "47", 0);//ACK nextion widget
}

void DataReceived() {
  terminal.print("Data Received : ");
  terminal.println(id);
  terminal.print("Return Data Value : ");
   int eos = data_from_nextion.indexOf(endChar);

  if (data_from_nextion.substring(0, 1) == "q") { //number
      for (int x = 0; x < 4; x++) {
      getDataUnion.getDataByteArray[x] = data_from_nextion[x + 1];
    }
    Return_Value = getDataUnion.getDataLong;
    terminal.println(Return_Value);
    terminal.flush();
    getDataUnion.getDataLong = 0;
    data_from_nextion = "";

    switch (id) {
      case 1:
        if (Return_Value > 150 && Return_Value < 260) {
          threshold1 = Return_Value / 10;
          Blynk.virtualWrite(V23, threshold1);
          Blynk.virtualWrite(V26, threshold1);

        }
        break;

      case 2:
        if (Return_Value > 100 && Return_Value < 165) {
          threshold2 = Return_Value / 10;
          Blynk.virtualWrite(V27, threshold2);
          Blynk.virtualWrite(V29, threshold2);
        }
        break;

      case 3:
        timer1 = Return_Value;
        break;

      case 4:
        timer2 = Return_Value;
        break;

      case 5:
        if (Return_Value == 1) {
          Blynk.virtualWrite(V34, HIGH);
          setOn = true;
        } else if (Return_Value == 0) {
          Blynk.virtualWrite(V34, LOW);
          setOn = false;
        }
        break;

      case 6:
        HI = Return_Value;
        break;

      case 7:
        Blynk.virtualWrite(V101, Return_Value);
        break;

      case 8:
        Blynk.virtualWrite(V103, Return_Value);
        break;

      case 9:
        Blynk.virtualWrite(V105, Return_Value);
        break;

      case 10:
        Blynk.virtualWrite(V107, Return_Value);
        break;

      case 11:
        startAt = (int)Return_Value * 60;
        break;

      case 12:
        stopAt = (int)Return_Value * 60;
        Blynk.virtualWrite(V100, startAt, stopAt, "Europe/Paris");
        break;

      case 13:
        startAt = (int)Return_Value * 60;
        break;

      case 14:
        stopAt = (int)Return_Value * 60;
        Blynk.virtualWrite(V102, startAt, stopAt, "Europe/Paris");
        break;

      case 15:
        startAt = (int)Return_Value * 60;
        break;

      case 16:
        stopAt = (int)Return_Value * 60;
        Blynk.virtualWrite(V104, startAt, stopAt, "Europe/Paris");
        break;

      case 17:
        startAt = (int)Return_Value * 60;
        break;

      case 18:
        stopAt = (int)Return_Value * 60;
        Blynk.virtualWrite(V106, startAt, stopAt, "Europe/Paris");
        break;
    }
  } else { // text received from Nextion
    String Return_Value = data_from_nextion.substring(1, eos);
    data_from_nextion = "";
    if (Return_Value == "auto") {
      Blynk.virtualWrite(V34, HIGH);
      setOn = true;
    } else if (Return_Value == "manuel") {
      Blynk.virtualWrite(V34, LOW);
      setOn = false;
    }
  }
}

ha ha ! :-p

3 years later :rofl:

@Blynk_Coeur Hey been awhile since we brought this one upā€¦ Iā€™m having an issue one of my variables for humidity set point keeps jumping to a random number after I input the number I want. I think it has something to do with having too many WriteStr or WriteNum calls because if I remove one it seems to work ok. Does that make sense? With the timers, buttons and pictures, plus indoor and outdoor humidity and temperature it looks like about 20 different calls to the functions you made. Just looking at yours it would seem like you are doing more do you have any idea what could be wrong? If you want I could post my code herd

1 Like

@daveblynk

I think your are right ,
I use timers and my void loop only contains blynk.run , ota , etc ā€¦, nothing about nextion

 ///////////////////////////////////// timers /////////////////////////////////////
  timer.setInterval(1000L, GetTime);// clock 
  timer.setInterval(10010L, TempUpdate);// read DHT11
  timer.setInterval(20020L, Gauge); // read fuel level
  timer.setInterval(21040L, Acquisition1);// read nextion1
  timer.setInterval(30050L, Acquisition2);// read nextion2
  timer.setInterval(40060L, Hvac);// Hvac control
  timer.setInterval(60070L, forecast);// call openweathermap.org
  timer.setInterval(70080L, connectionstatus);// check wifi


void loop() {
  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and not already trying to reconnect, set timer to try to reconnect in 60 seconds
    ReCnctFlag = 1;  // Set reconnection Flag
    timer.setTimeout(60000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      Blynk.connect();  // Try to reconnect to the server
    });  // END Timer Function
  }
  timer.run();
  ArduinoOTA.handle();  // For OTA
}

Ok so I think I found my problem. I was using a char strTime[16];

sprintf(strTime,"time.txt=\"%u:%02u PM\"\xFF\xFF\xFF",hourFormat,minute());

Which is easy to create an array, however I think this was some how messing with my stored int variable for humidity set point. I think it has something to do with pointers but I canā€™t wrap my head around it.

I changed this to :

StrTime = StrTime + ":" + strMinute;

and now my setPoint variable doesnā€™t change.

EDIT **I think maybe the problem was the size of the char I didnā€™t count the FFs in the size. I am trying [35] and the sprintf statement seems to be working. **

1 Like

Hi @daveblynk I was trying to use a Python HTTP server (for something different) and followed your instructions in post #18
Step 4 confused me, as I thought I was supposed to be typing the IP address and port into the CMD window. I wasnā€™t until I googled how to do this that I realised that this was in a browser window (makes sense of course - in hindsight :crazy_face:).

So, I used my moderatorā€™s superpowers :man_superhero: to edit your post and add the bit in bold below - just so that itā€™s easier for others to follow in futureā€¦

Hope thatā€™s okay with you. How is this Nextion OTA stuff working for you now?

Pete.

2 Likes

No problem!

I have been just OTAing the basic NextionOTA sketch when I do some changes to the GUI. Then after that, OTAing the Blynk sketch back onto the device. Saves taking the box apart but still isnā€™t ideal. I have no idea why it work earlier to us a virtual pin to trigger the NextionOTA but now it refuses.

1 Like

@Blynk_Coeur you got your two ā€œcylinderā€ esp32 yet? When I get settled back into a home again I want to order some dev boards (home drawn PCBs) for my D1 mini 32s and get serious about some projects. Still tuning your thermostat? Youā€™ll have to try Nextion OTA with the new blynk library and let me know if it still conflicts.

I have 4 ESP32, one for thermostat, one for boiler control ,one for 433Mhz and one for ext temp and fuel level

I didnā€™t try Nexion OTA with new library.

I am stuck with basic code as date , time , DST
I am using NTP Client, but itā€™s not so easy as time widget.

and I donā€™t know how to bridge my 4 MCU

Have you looked at the NTP library from ā€œthe guy with the Swiss accentā€ā€¦

Iā€™ve not used it, but some people have said itā€™s very easy.

Pete.

1 Like

Do you not just subscribe to different data streams on the different devices?

Good idea, I will try Andreas Spiess 's library 2021-06-09_220136