Nextion display plugin

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#51 Post by ledfreak3d » 17 Nov 2016, 08:31

I think I might have one or 2 laying around let me check tonight

both the esp07 and 12 and 12e fit on there I think I have both of them
think I have one or 2 ones that have not been populated yet
Domoticz Synology Esp easy Location Netherlands /Hoorn

rhannink
Normal user
Posts: 7
Joined: 14 Nov 2016, 10:49

Re: Nextion display plugin

#52 Post by rhannink » 17 Nov 2016, 09:35

Hello,

If you have any extra pcb's you like to sell, please let me know. Iam working on building a Nextion/RFID alarm panel based on ESP8266 and Domoticz.
I prefer the populated boards, but bare prints would also do.

With kind regards,

Remco
Last edited by rhannink on 17 Nov 2016, 10:07, edited 1 time in total.

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#53 Post by ledfreak3d » 17 Nov 2016, 09:41

Hey Remco.

I will check tonight im sure I have some unpopulated and some populated ones
are you based in the Netherlands ?
Domoticz Synology Esp easy Location Netherlands /Hoorn

rhannink
Normal user
Posts: 7
Joined: 14 Nov 2016, 10:49

Re: Nextion display plugin

#54 Post by rhannink » 17 Nov 2016, 10:08

Yep,

Based in Netherlands, Overijssel

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#55 Post by ledfreak3d » 17 Nov 2016, 10:11

thought so ;)

if anybody is interested can put in a new order of boards
ill check tonight how many I still have
still have enough components to make more boards but don't have any esp12e's or buttons at the moment .

still thinking about making a custome domoticz sensor board
eather with esp8266 or a atmel / nrf combo for my sensors
Domoticz Synology Esp easy Location Netherlands /Hoorn

xbmcnut
Normal user
Posts: 49
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: Nextion display plugin

#56 Post by xbmcnut » 17 Nov 2016, 10:48

ledfreak3d wrote:thought so ;)

if anybody is interested can put in a new order of boards
ill check tonight how many I still have
still have enough components to make more boards but don't have any esp12e's or buttons at the moment .

still thinking about making a custome domoticz sensor board
eather with esp8266 or a atmel / nrf combo for my sensors
I'd be keen on a couple of populated or partly populated boards but I live in NZ.
Numerous Sonoff's and Shelly's, Home Assistant on Intel NUC i3, Aeotec Z-Stick (Gen 5), deCONZ Zigbee Stick, 3 x Echo Dot's and 5 x Google Home

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#57 Post by ledfreak3d » 17 Nov 2016, 11:48

need to get me a decent hot air station to do smd properly
now doing it with a normal soldering iron its doable but its not prety
Domoticz Synology Esp easy Location Netherlands /Hoorn

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#58 Post by ledfreak3d » 18 Nov 2016, 07:15

Double checked.
I have 4 unpopulated boards and
2 populated with a esp07 on it
Domoticz Synology Esp easy Location Netherlands /Hoorn

xbmcnut
Normal user
Posts: 49
Joined: 17 Mar 2016, 08:49
Location: Auckland, NZ
Contact:

Re: Nextion display plugin

#59 Post by xbmcnut » 18 Nov 2016, 11:55

ledfreak3d wrote:Double checked.
I have 4 unpopulated boards and
2 populated with a esp07 on it
Would you post one of the populated boards to NZ to allow me to test? I can pay with PayPal or Amazon UK gift card. Understand if it's too much hassle. ;)
Numerous Sonoff's and Shelly's, Home Assistant on Intel NUC i3, Aeotec Z-Stick (Gen 5), deCONZ Zigbee Stick, 3 x Echo Dot's and 5 x Google Home

rhannink
Normal user
Posts: 7
Joined: 14 Nov 2016, 10:49

Re: Nextion display plugin

#60 Post by rhannink » 18 Nov 2016, 12:01

I like to have one populated and one unpopulated board if possible.

Gr. Remco

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#61 Post by BertB » 18 Nov 2016, 13:15

What is the advantage of this Board over a wemos d1?

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#62 Post by ledfreak3d » 18 Nov 2016, 16:12

xbmcnut wrote:
ledfreak3d wrote:Double checked.
I have 4 unpopulated boards and
2 populated with a esp07 on it
Would you post one of the populated boards to NZ to allow me to test? I can pay with PayPal or Amazon UK gift card. Understand if it's too much hassle. ;)
should be no problem

please contact me on email if anybody is interested in a board

ledfreak3d@gmail.com
Domoticz Synology Esp easy Location Netherlands /Hoorn

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#63 Post by BertB » 25 Nov 2016, 10:11

Any new developments here?

User avatar
ledfreak3d
Normal user
Posts: 48
Joined: 21 Oct 2016, 12:41

Re: Nextion display plugin

#64 Post by ledfreak3d » 25 Nov 2016, 10:18

Working on it
Domoticz Synology Esp easy Location Netherlands /Hoorn

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#65 Post by BertB » 25 Nov 2016, 10:30

What direction are you heading to?

vmfs1968
Normal user
Posts: 42
Joined: 18 Oct 2015, 23:51

Re: Nextion display plugin

#66 Post by vmfs1968 » 06 Dec 2016, 11:24

BertB wrote:I also created a screen for the display itself.

Winscreen.png
Hello
Friend can help?
I bought a 2.4 display and I can not seem to get it working
Compiled the plugin without problems in esp, but it does not give
Do I need to put any software on the display?

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#67 Post by BertB » 06 Dec 2016, 11:32

Yes, you have to download the ide from Nextion. In there you need to create objects like a textbox, where you can send data to. There are tutorials on the internet. Just search for Nextion and arduino.

vmfs1968
Normal user
Posts: 42
Joined: 18 Oct 2015, 23:51

Re: Nextion display plugin

#68 Post by vmfs1968 » 07 Dec 2016, 12:42

BertB wrote:Yes, you have to download the ide from Nextion. In there you need to create objects like a textbox, where you can send data to. There are tutorials on the internet. Just search for Nextion and arduino.

thank you so much
I already got it, it's working very well.

vmfs1968
Normal user
Posts: 42
Joined: 18 Oct 2015, 23:51

Re: Nextion display plugin

#69 Post by vmfs1968 » 10 Dec 2016, 18:50

Hello
It is possible through the touch a button in the nextion to send a command to the domoticz?
To then at least enable and disable a gpio on the esp8266 board?

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#70 Post by nick-head » 13 Dec 2016, 18:56

Hi,

I am using the previously mentioned Nextion Plugin (104) and came across a problem.

I cannot output to a n? number if it's below 100, unless I put zero's in front to
make a 3 digit number. Like 001, 073 etc.

Any idea what I am doing wrong ?

Regards

Nick

PS, I am using an ESP8266 NodeMCU V0.9. This maybe the problem, I will try on a 1.0 later on and report back
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#71 Post by nick-head » 13 Dec 2016, 20:52

Well,

Just tried it with ESPEasy 147 on a nodemcu v 1.0 and it does the same.

Can't understand this a tall
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

vmfs1968
Normal user
Posts: 42
Joined: 18 Oct 2015, 23:51

Re: Nextion display plugin

#72 Post by vmfs1968 » 13 Dec 2016, 23:29

nick-head wrote:Well,

Just tried it with ESPEasy 147 on a nodemcu v 1.0 and it does the same.

Can't understand this a tall
I am compiling without problems
You have to inside the ESPEasy file _104.ino

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#73 Post by BertB » 14 Dec 2016, 21:25

nick-head wrote:Hi,

I am using the previously mentioned Nextion Plugin (104) and came across a problem.

I cannot output to a n? number if it's below 100, unless I put zero's in front to
make a 3 digit number. Like 001, 073 etc.

Any idea what I am doing wrong ?

Regards

Nick

PS, I am using an ESP8266 NodeMCU V0.9. This maybe the problem, I will try on a 1.0 later on and report back
I have the same problem. Need to dig into this.

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#74 Post by nick-head » 01 Jan 2017, 19:03

Anyone found out why this is happening ?
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#75 Post by BertB » 01 Jan 2017, 21:05

nick-head wrote:Anyone found out why this is happening ?
Yes. I tried to put the entire file in the ESP8266nu/ESPEasyPluginPlayground. Hope I took the right steps.
In the mean time, hereunder the new code.

Code: Select all

#include <Arduino.h>
#include <SoftwareSerial.h>

//#######################################################################################################
//#################################### Plugin 117: Nextion <info@sensorio.cz>  ###########################
//#######################################################################################################

#define PLUGIN_117
#define PLUGIN_ID_117 117
#define PLUGIN_NAME_117 "Display: Nextion"
#define PLUGIN_VALUENAME1_117 "code"
unsigned long Plugin_117_code = 0;
int8_t Plugin_117_RXpin = -1;
int8_t Plugin_117_TXpin = -1;

SoftwareSerial *nextion;

boolean Plugin_117(byte function, struct EventStruct *event, String &string) {
  boolean success = false;
  static byte displayTimer = 0;

  switch (function) {

    case PLUGIN_DEVICE_ADD: {
      Device[++deviceCount].Number = PLUGIN_ID_117;

      Device[deviceCount].Type = DEVICE_TYPE_DUAL;
      Device[deviceCount].VType = SENSOR_TYPE_QUAD;
      Device[deviceCount].Ports = 0;
      Device[deviceCount].PullUpOption = true;
      Device[deviceCount].InverseLogicOption = false;
      Device[deviceCount].FormulaOption = false;
      Device[deviceCount].ValueCount = 4;
      Device[deviceCount].SendDataOption = true;
      Device[deviceCount].TimerOption = true;
      Device[deviceCount].GlobalSyncOption = true;

      break;
    }

    case PLUGIN_GET_DEVICENAME: {
      string = F(PLUGIN_NAME_117);
      break;
    }

    case PLUGIN_GET_DEVICEVALUENAMES: {
      strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0],PSTR(PLUGIN_VALUENAME1_117));
      break;
    }
    
    case PLUGIN_TEN_PER_SECOND: {
      char __buffer[80];

      uint16_t i;
      uint8_t c;
      while (nextion->available() > 0) {
        delay(10);
        c = nextion->read();
        
        if (0x65 == c) {
          if (nextion->available() >= 6) {
            __buffer[0] = c;
            for (i = 1; i < 7; i++) {
              __buffer[i] = nextion->read();
            }

            __buffer[i] = 0x00;

            if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) {
              Plugin_117_code = ((__buffer[1] >> 8) & __buffer[2] >> 8) & __buffer[3];
              UserVar[event->BaseVarIndex] = __buffer[1] * 256 + __buffer[2];
              UserVar[event->BaseVarIndex + 1] = __buffer[3];
              String log = F("Nextion : code: ");
              log += __buffer[1];
              log += ",";
              log += __buffer[2];
              log += ",";
              log += __buffer[3];

              addLog(LOG_LEVEL_INFO, log);
              sendData(event);
            }
          }
        } else {

          if (c == 's') {
            i = 1;
            __buffer[0] = c;
            c=0;
            while (nextion->available() > 0) {
              __buffer[i++] = nextion->read();
              Serial.write((char)__buffer[i]);
            }
            Serial.println();
            __buffer[i] = 0x00;

            UserVar[event->BaseVarIndex] = __buffer[2];
            UserVar[event->BaseVarIndex+1] = __buffer[3];
            UserVar[event->BaseVarIndex+2] = __buffer[4];
            UserVar[event->BaseVarIndex+3] = __buffer[5];

            String log = F("Nextion : send command: ");
            log += __buffer;
            log += UserVar[event->BaseVarIndex];
            addLog(LOG_LEVEL_INFO, log);
            
            ExecuteCommand(VALUE_SOURCE_SYSTEM, __buffer);
          }
        }
      }

      if (Settings.TaskDevicePin3[event->TaskIndex] != -1) {
        if (!digitalRead(Settings.TaskDevicePin3[event->TaskIndex])) {
          Plugin_117_displayOn();
          displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        }
      }

      success = true;
      break;
    }

    case PLUGIN_ONCE_A_SECOND: {
      if ( displayTimer > 0) {
        displayTimer--;
        if (displayTimer == 0)
          Plugin_117_displayOff();
        }
        break;
      }


    case PLUGIN_WEBFORM_SAVE: {

      String plugin1 = WebServer.arg("plugin_117_timer");
      Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
      String plugin2 = WebServer.arg("plugin_117_rxwait");
      Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin2.toInt();
      String plugin3 = WebServer.arg("plugin_117_events");
      Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin3.toInt();
      String plugin4 = WebServer.arg("plugin_117_sensortype");
      Settings.TaskDevicePluginConfig[event->TaskIndex][3] = plugin4.toInt();

      char deviceTemplate[8][64];
      for (byte varNr = 0; varNr < 8; varNr++) {
        char argc[25];
        String arg = F("Plugin_117_template");
        arg += varNr + 1;
        arg.toCharArray(argc, 25);
        String tmpString = WebServer.arg(argc);
        strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
      }

//      Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

      SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
    
      success = true;
      break;
    }


    case PLUGIN_WEBFORM_LOAD: {

      char tmpString[128];

      char deviceTemplate[8][64];
      LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
      for (byte varNr = 0; varNr < 8; varNr++)
        {
          string += F("<TR><TD>Line ");
          string += varNr + 1;
          string += F(":<TD><input type='text'li size='50' maxlength='50' name='Plugin_117_template");
          string += varNr + 1;
          string += F("' value='");
          string += deviceTemplate[varNr];
          string += F("'>");
        }

      string += F("<TR><TD>Display button:<TD>");
      addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);

      sprintf_P(tmpString, PSTR("<TR><TD>Display Timeout:<TD><input type='text' name='plugin_117_timer' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
      string += tmpString;

      success = true;
      break;
    }

    case PLUGIN_INIT: {

      LoadTaskSettings(event->TaskIndex);
//      if ((ExtraTaskSettings.TaskDevicePluginConfigLong[0] != 0) && (ExtraTaskSettings.TaskDevicePluginConfigLong[1] != 0)) {
//      if (Settings.TaskDevicePin1[event->TaskIndex] != -1) {
//        pinMode(Settings.TaskDevicePin1[event->TaskIndex], OUTPUT);
//       digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
//        delay(500);
//        digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
//        pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
//      }

      displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
      if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], INPUT_PULLUP);

      if (Settings.TaskDevicePin1[event->TaskIndex] != -1)
        {
          Plugin_117_RXpin = Settings.TaskDevicePin1[event->TaskIndex];
//          pinMode(Plugin_117_RXpin, INPUT_PULLUP);
//          attachInterrupt(Plugin_117_RXpin, RF_ISR, CHANGE);
          success = true;
        }

      if (Settings.TaskDevicePin2[event->TaskIndex] != -1)
        {
          Plugin_117_TXpin = Settings.TaskDevicePin2[event->TaskIndex];
//          pinMode(Plugin_117_TXpin, OUTPUT);
        }
      
      if (!nextion) {
//        nextion = new SoftwareSerial(13,14);
        nextion = new SoftwareSerial(Plugin_117_RXpin , Plugin_117_TXpin);
      }

      Serial.print("pin: ");
      Serial.println(Settings.TaskDevicePin1[event->TaskIndex]);

      nextion->begin(9600);

      success = true;
      break;
    }

    case PLUGIN_READ: {
        char deviceTemplate[8][64];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));

        for (byte x = 0; x < 8; x++) {
          String tmpString = deviceTemplate[x];
          if (tmpString.length()) {
            String newString = parseTemplate(tmpString, 0);
            Serial.println(newString);

            sendCommand(newString.c_str());
            }
        }
        success = false;
        break;
      }


    case PLUGIN_WRITE: {
      String tmpString = string;
      int argIndex = tmpString.indexOf(',');
      if (argIndex)
        tmpString = tmpString.substring(0, argIndex);
      if (tmpString.equalsIgnoreCase(F("NEXTION"))) {
        argIndex = string.indexOf(',');
        tmpString = string.substring(argIndex + 1);

        sendCommand(tmpString.c_str());

        Serial.println(tmpString);
        success = true;
      }
      break;
    }
  }
  return success;
}




void Plugin_117_displayOn() {
}

void Plugin_117_displayOff() {
  
}

void sendCommand(const char *cmd) {
  nextion->print(cmd);
  nextion->write(0xff);
  nextion->write(0xff);
  nextion->write(0xff);
}

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#76 Post by nick-head » 01 Jan 2017, 21:52

Nice one Bert,

I am just in the process of uploading to the ESP.

Right, uploaded. Had to remove original plugin as it has redefinitions of SoftwarSerial and other things.

OK, done.

Can't find RX/TX as before. Can't even make it produce anything on the screen.

Totally different interface. Will have to look later, I may have done something wrong at my end.
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#77 Post by BertB » 01 Jan 2017, 22:42

nick-head wrote:Nice one Bert,

I am just in the process of uploading to the ESP.

Right, uploaded. Had to remove original plugin as it has redefinitions of SoftwarSerial and other things.

OK, done.

Can't find RX/TX as before. Can't even make it produce anything on the screen.

Totally different interface. Will have to look later, I may have done something wrong at my end.
I found that the originale interface did not work anymore, so I had to change it.
1st GPIO is now Rx and 2nd GPIO Tx.
Sorry for the inconvenience, but please do not forget, I am only trying to persuade more professional programmers to make ik more beautiful :)

IDX/Var is not yet functional and neither are Display button and Display Timeout.

You can send commands and data to it:
http://espeasy-ip/control?cmd=NEXTION,rest ====> resets the display
http://espeasy-ip/control?cmd=NEXTION,dim=50 ====> dims the backlight to 50%
http://espeasy-ip/control?cmd=NEXTION,page0.n0.val=12 ====> sets the value of n0 on page 0 to 12
http://espeasy-ip/control?cmd=NEXTION,page0.t5.txt="hoi" ====> sets the text of t0 on page 0 to hoi
Attachments
P104_IF.png
P104_IF.png (58.8 KiB) Viewed 7463 times

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#78 Post by nick-head » 01 Jan 2017, 22:56

No problem Bert,

I have only been experimenting with the plugins for a few days and I have learnt a few things.

I have great respect for any developers who commit their time to produce "free" software based
on ideas generated by many people.

I am using ESPeasy in my home automation system and I have a lot to learn.

Thanks for your time and help.

Nick
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

nick-head
Normal user
Posts: 41
Joined: 15 Nov 2016, 11:09
Location: North East UK

Re: Nextion display plugin

#79 Post by nick-head » 01 Jan 2017, 23:19

That has cured the <100 problem Bert, works absolutely fine now.

now I have to find something to do with it now.

Thanks Bert, your a star.

Regards

Nick
ESP32, Arduino's,Raspberry Pi's, ESP8266's, Nextion's, Sonoff's, LightWaveRF's, RFXCom 433, and a headache
And a HackRF One, as a present to myself.

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#80 Post by BertB » 01 Jan 2017, 23:23

nick-head wrote:That has cured the <100 problem Bert, works absolutely fine now.

now I have to find something to do with it now.

Thanks Bert, your a star.

Regards

Nick
Glad tot be of help,

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#81 Post by Jeff » 05 Jan 2017, 22:07

Hello,
Congratulations for this development. I bought a direct nextion when i discovered it. :D
I try this plugin for a few days and I can not. :(
I created a page, a text box, a value box and a gauge.
I have compiled the last plugin on this page 8 and others before.
I plugged the RX on GPIO13- D7 and TX on GPIO14-D5
It does not communicate, I try the lines or the rules.
Ex line 1: page0.n0.val = 20
Line 2 : page0.t0.txt="[ds18b20#TEMPERATURE]"

Rules :
On ds18b20#TEMPERATURE do
NEXTION,t0.txt="[ds18b20#TEMPERATURE]"
endon

What I forgot ? Thanks

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#82 Post by BertB » 06 Jan 2017, 08:09

Hi, sorry to hear it does not work for you.
I assume you can see the setup page in devices in ESPEasy?
And that you can set GPIO 1 and GPIO 2
And that you did not mix up Tx and Rx?

What hardware do you use?

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#83 Post by Jeff » 06 Jan 2017, 13:39

Thx for your help.
I use a wemos d1 mini.
I paste the sketch in espeay.ino with plugin p117... I compile, it's good. I upload.
Yes i can see the configuration page with the gpio.
I configure the gpio for the rx and tx, not error.
I made a page on the nextion with try a block t0, n0, z0...
I write on in the line 1, line 2....and with rules to try...

What is the wiring ? Need a special library, i have nextion library and i didn't error when i compile, special serial 9600 ou?
Configuration espeasy : domoticz mqtt, spi, configuration pin ?

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#84 Post by BertB » 06 Jan 2017, 13:53

I do not use the Nextion library.
The Nextion itself is a basic model.

The Nextion requires 5 volt power and the ESP 8266 can only handle up to 3.3 volt.
On the Tx pin of the Wemos, you can connect the Rx of the Nextion.
On the Rx pin you need a voltage limiter, because the voltage of the Nextion Tx pin is 5 volts.
For that purpose I use a small signal, high speed diode and a resistor. 1n4448 or so will do fine.


Kathode to Tx of Nextion.
Anode to Rx of Wemos
Resistor of some 10 k or so from Rx of Wemos to + 3.3 volt of Wemos.

You can also try an use the Nextion IDE with a USB to serial converterd to test the Nextion.

User avatar
Binder
Normal user
Posts: 10
Joined: 06 Jan 2017, 13:17
Location: Germany

Re: Nextion display plugin

#85 Post by Binder » 06 Jan 2017, 14:32

Hi Bert,

I think I'm having a similar (or the same) problem as Jeff.

I tried your plugin with a plain esp-12f or a nodemcu-V2.
The pins I use are GPIO13 und 14 (D7 and D5).

The pins itself are functional: for a test I changed the device to a switch and shortened them to ground. success.

Then I connected an FTDI to the pins and there is nothing. It doesn't matter if I use the URL with control?cmd=NEXTION,dim=0 or something in the device configuration. The control window always stays empty. It seems the plugin does not use the configured pins.

The hardware must be ok. For the next test I uploaded the firmware esplink, and then I saw communication on the wire.

Do you have another idea what I can check?

regards
Pete

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#86 Post by BertB » 06 Jan 2017, 14:34

I will start with a fresh wemos to test.

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#87 Post by BertB » 06 Jan 2017, 14:47

You could also try to change a part of the code and re compile:

Change:
if (!nextion) {
// nextion = new SoftwareSerial(13,14);
nextion = new SoftwareSerial(Plugin_117_RXpin , Plugin_117_TXpin);
}

into:

if (!nextion) {
nextion = new SoftwareSerial(13,14);
// nextion = new SoftwareSerial(Plugin_117_RXpin , Plugin_117_TXpin);
}

Per haps something goes wrong with the pin assignment.
SPI has to be disabled.

User avatar
Binder
Normal user
Posts: 10
Joined: 06 Jan 2017, 13:17
Location: Germany

Re: Nextion display plugin

#88 Post by Binder » 06 Jan 2017, 15:23

Hi Bert,
it works now. Thanks for your quick workaround.

regards

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#89 Post by Jeff » 06 Jan 2017, 20:57

Thank you for the time.
I understand a little better but I still have questions.
The tx and the rx of the nextion, is it connected to the tx and the rx of the wemos or the GPIO 13 and 14 of the wemos ?
The 5v on the 3.3v, I had not seen my mistake
level.png
level.png (13.94 KiB) Viewed 13843 times
D3 : 1n4007
R2 : 10K

I have ordered a level swicher since, 60 days have not arrived!
The pins itself are functional: for a test I changed the device to a switch and shortened them to ground. success.
It work
You can also try an use the Nextion IDE with a USB to serial converterd to test the Nextion.
It work

I recompiled, tried my editing on 13 and 14 with your proposition but nothing, I tried other GPIOs, nothing either.

My program nextion is it good ? I draw a txt (t0), a number (N0) and a jauge (Z0) !

I go to ski tomorrow, we will see my return :D

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#90 Post by BertB » 07 Jan 2017, 18:08

For only sending data from the Wemos to the Nextion, Rx on the Wemos (Blue wire) is not required.

This is how I connect my nextion.
You can choose to feed it from a strong (Nextion requires sufficient power) usb or an external 5 volt DC power supply.
I tested it with a 1n4448 and a 1n4004 diode.
the colors are the colors of the Nextion cable, where:
blue = Tx (Nextion)
yellow = Rx (Nextion)
red = + 5v
black = gnd

It can be necessary to add capacitors.
Nextion1_Sbb.jpg
Nextion1_Sbb.jpg (42.8 KiB) Viewed 13797 times

Allycat1972
Normal user
Posts: 25
Joined: 19 Apr 2016, 11:12

Re: Nextion display plugin

#91 Post by Allycat1972 » 08 Jan 2017, 14:12

Hi everyone.

So glad this has been developed. I am going to replace my previous incarnation of Heating Thermostat (using a sonoff TH) with this Nextion. I have used Scargills PCB and screen design (modified) with a relay board and small PSU from a phone charger.

The advantage of Scargills board is that is has all the breakouts purposely positioned and also screws to the back of the Nextion screen making it compact.

I added the MQTT Import utility so I can pick up my Heating setpoint and display it along side the Temperature and Humidity from the DHT22 mounted at the bottom. I also brought up the Relay status (light on the right)
IMG_2143.JPG
IMG_2143.JPG (105 KiB) Viewed 12888 times
IMG_2144.JPG
IMG_2144.JPG (137.02 KiB) Viewed 12888 times

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#92 Post by Jeff » 08 Jan 2017, 18:39

BertB wrote:For only sending data from the Wemos to the Nextion, Rx on the Wemos (Blue wire) is not required.

This is how I connect my nextion.
You can choose to feed it from a strong (Nextion requires sufficient power) usb or an external 5 volt DC power supply.
I tested it with a 1n4448 and a 1n4004 diode.
the colors are the colors of the Nextion cable, where:
blue = Tx (Nextion)
yellow = Rx (Nextion)
red = + 5v
black = gnd

It can be necessary to add capacitors.

Nextion1_Sbb.jpg
Thank you for help me.
My wiring was not good for Tx. I use an external 5 volt power.
I'll try to my come back.

If some would like to share their hmi project, it would be great.

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#93 Post by Jeff » 15 Jan 2017, 22:50

Yes it work :mrgreen:
Thanks @BertB

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#94 Post by Jeff » 16 Jan 2017, 21:04

Hello,

I know how to handle texts and retrieve values ​​via mqtt :D
How do you do the buttons to send a command to domoticz ?

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#95 Post by BertB » 16 Jan 2017, 22:50

I am trying to get the input from buttons as follows:
For example, in the Nextion, I have put the following lines in the Tough Release Event section of a button:
if(va1.val==0)
{
va1.val=1
print "|s"
print "idx=99&switchcmd=On"
printh 0a
}else
{
va1.val=0
print "|s"
print "idx=99&switchcmd=Off"
printh 0x0a
}
I use variable va1 as a toggle state memory.
Anyway, the idea is that the Nextion sends idx=99&switchcmd=On en idx=99&switchcmd=Off.

Those values I can now project in the variables of the Nextion plugin. Now I am trying to send those values to Domoticz.
Since I am a self tought programmer, this is not a fast creation process.

Herunder is the accompaniing plugin code. I still do not get it in the playground.

Code: Select all

#include <Arduino.h>
#include <SoftwareSerial.h>

//#######################################################################################################
//#################################### Plugin 117: Nextion <info@sensorio.cz>  ###########################
//#######################################################################################################

#define PLUGIN_117
#define PLUGIN_ID_117 117
#define PLUGIN_NAME_117 "Display: Nextion"
#define PLUGIN_VALUENAME1_117 "code"
unsigned long Plugin_117_code = 0;
int8_t Plugin_117_RXpin = -1;
int8_t Plugin_117_TXpin = -1;

SoftwareSerial *nextion;

boolean Plugin_117(byte function, struct EventStruct *event, String &string) {
  boolean success = false;
  static byte displayTimer = 0;

  switch (function) {

    case PLUGIN_DEVICE_ADD: {
      Device[++deviceCount].Number = PLUGIN_ID_117;

      Device[deviceCount].Type = DEVICE_TYPE_DUAL;
      Device[deviceCount].VType = SENSOR_TYPE_QUAD;
      Device[deviceCount].Ports = 0;
      Device[deviceCount].PullUpOption = true;
      Device[deviceCount].InverseLogicOption = false;
      Device[deviceCount].FormulaOption = false;
      Device[deviceCount].ValueCount = 4;
      Device[deviceCount].SendDataOption = true;
      Device[deviceCount].TimerOption = true;
      Device[deviceCount].GlobalSyncOption = true;

      break;
    }

    case PLUGIN_GET_DEVICENAME: {
      string = F(PLUGIN_NAME_117);
      break;
    }

    case PLUGIN_GET_DEVICEVALUENAMES: {
      strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0],PSTR(PLUGIN_VALUENAME1_117));
      break;
    }
    
    case PLUGIN_TEN_PER_SECOND: {
      char __buffer[80];

      uint16_t i;
      uint8_t c;
      String Vidx;
      String Nvalue;
      String Svalue;
      String Nswitch;
      
      while (nextion->available() > 0) {
        delay(10);
        c = nextion->read();
        
        if (0x65 == c) {
          if (nextion->available() >= 6) {
            __buffer[0] = c;
            for (i = 1; i < 7; i++) {
              __buffer[i] = nextion->read();
            }

            __buffer[i] = 0x00;

            if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) {
              Plugin_117_code = ((__buffer[1] >> 8) & __buffer[2] >> 8) & __buffer[3];
              UserVar[event->BaseVarIndex] = __buffer[1] * 256 + __buffer[2];
              UserVar[event->BaseVarIndex + 1] = __buffer[3];
              String log = F("Nextion : code: ");
              log += __buffer[1];
              log += ",";
              log += __buffer[2];
              log += ",";
              log += __buffer[3];

              addLog(LOG_LEVEL_INFO, log);
              sendData(event);
            }
          }
        } else {

          if (c == '|') {
            i = 1;
            __buffer[0] = c;
            c=0;
            while (nextion->available() > 0) {
              __buffer[i] = nextion->read();
              Serial.write((char)__buffer[i]);
              if (__buffer[i]==0x0d) break;
              i++;
            }
            Serial.println("end");
            __buffer[i] = 0x00;

            String tmpString = __buffer;

            int argIndex = tmpString.indexOf("idx=");
            int argEnd = tmpString.indexOf('&');
            if (argIndex)
            Vidx = tmpString.substring(argIndex + 4,argEnd);

            switch (__buffer[1]){
            
              case 'u':

                argIndex = tmpString.indexOf("nvalue=");
                argEnd = tmpString.indexOf('&',argIndex);
                if (argIndex)
                  Nvalue = tmpString.substring(argIndex + 7,argEnd);

                argIndex = tmpString.indexOf("svalue=",argIndex);
                argEnd = tmpString.indexOf(0x0a);
                if (argIndex)
                  Svalue = tmpString.substring(argIndex + 7,argEnd);
                
                break;

              case 's':
      
                argIndex = tmpString.indexOf("switchcmd=",argIndex);
                argEnd = tmpString.indexOf(0x0a);
                if (argIndex)
                  Nvalue = tmpString.substring(argIndex + 10,argEnd);
                if (Nvalue=="On")
                  Nswitch='1';
                if (Nvalue=="Off")
                  Nswitch='0';

                break;
      
            }

//    }
//        tmpString = tmpString.substring(0, argIndex);
//      if (tmpString.equalsIgnoreCase(F("NEXTION"))) {
//        argIndex = string.indexOf(',');
//        tmpString = string.substring(argIndex + 1);
//
//        sendCommand(tmpString.c_str());
//
        
//        success = true;
            Serial.println(tmpString);
            Serial.println(Vidx);
            Serial.println(Nvalue);
            Serial.println(Svalue);
            Serial.println(Nswitch);

            UserVar[event->BaseVarIndex] = Vidx.toFloat();
            UserVar[event->BaseVarIndex+1] = Nvalue.toFloat();
            UserVar[event->BaseVarIndex+2] = Svalue.toFloat();
            UserVar[event->BaseVarIndex+3] = Nswitch.toFloat();

            String log = F("Nextion : send command: ");
            log += __buffer;
            log += UserVar[event->BaseVarIndex];
            addLog(LOG_LEVEL_INFO, log);
            
            ExecuteCommand(VALUE_SOURCE_SYSTEM, __buffer);
          }
        }
      }

      if (Settings.TaskDevicePin3[event->TaskIndex] != -1) {
        if (!digitalRead(Settings.TaskDevicePin3[event->TaskIndex])) {
          Plugin_117_displayOn();
          displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
        }
      }

      success = true;
      break;
    }

    case PLUGIN_ONCE_A_SECOND: {
      if ( displayTimer > 0) {
        displayTimer--;
        if (displayTimer == 0)
          Plugin_117_displayOff();
        }
        break;
      }


    case PLUGIN_WEBFORM_SAVE: {

      String plugin1 = WebServer.arg("plugin_117_timer");
      Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
      String plugin2 = WebServer.arg("plugin_117_rxwait");
      Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin2.toInt();
      String plugin3 = WebServer.arg("plugin_117_events");
      Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin3.toInt();
      String plugin4 = WebServer.arg("plugin_117_sensortype");
      Settings.TaskDevicePluginConfig[event->TaskIndex][3] = plugin4.toInt();

      char deviceTemplate[8][64];
      for (byte varNr = 0; varNr < 8; varNr++) {
        char argc[25];
        String arg = F("Plugin_117_template");
        arg += varNr + 1;
        arg.toCharArray(argc, 25);
        String tmpString = WebServer.arg(argc);
        strncpy(deviceTemplate[varNr], tmpString.c_str(), sizeof(deviceTemplate[varNr]));
      }

//      Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value

      SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
    
      success = true;
      break;
    }


    case PLUGIN_WEBFORM_LOAD: {

      char tmpString[128];

      char deviceTemplate[8][64];
      LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
      for (byte varNr = 0; varNr < 8; varNr++)
        {
          string += F("<TR><TD>Line ");
          string += varNr + 1;
          string += F(":<TD><input type='text'li size='50' maxlength='50' name='Plugin_117_template");
          string += varNr + 1;
          string += F("' value='");
          string += deviceTemplate[varNr];
          string += F("'>");
        }

      string += F("<TR><TD>Display button:<TD>");
      addPinSelect(false, string, "taskdevicepin3", Settings.TaskDevicePin3[event->TaskIndex]);

      sprintf_P(tmpString, PSTR("<TR><TD>Display Timeout:<TD><input type='text' name='plugin_117_timer' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][2]);
      string += tmpString;

      success = true;
      break;
    }

    case PLUGIN_INIT: {

      LoadTaskSettings(event->TaskIndex);
//      if ((ExtraTaskSettings.TaskDevicePluginConfigLong[0] != 0) && (ExtraTaskSettings.TaskDevicePluginConfigLong[1] != 0)) {
//      if (Settings.TaskDevicePin1[event->TaskIndex] != -1) {
//        pinMode(Settings.TaskDevicePin1[event->TaskIndex], OUTPUT);
//       digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], LOW);
//        delay(500);
//        digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
//        pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
//      }

      displayTimer = Settings.TaskDevicePluginConfig[event->TaskIndex][2];
      if (Settings.TaskDevicePin3[event->TaskIndex] != -1)
          pinMode(Settings.TaskDevicePin3[event->TaskIndex], INPUT_PULLUP);

      if (Settings.TaskDevicePin1[event->TaskIndex] != -1)
        {
          Plugin_117_RXpin = Settings.TaskDevicePin1[event->TaskIndex];
//          pinMode(Plugin_117_RXpin, INPUT_PULLUP);
//          attachInterrupt(Plugin_117_RXpin, RF_ISR, CHANGE);
          success = true;
        }

      if (Settings.TaskDevicePin2[event->TaskIndex] != -1)
        {
          Plugin_117_TXpin = Settings.TaskDevicePin2[event->TaskIndex];
//          pinMode(Plugin_117_TXpin, OUTPUT);
        }
      
      if (!nextion) {
        nextion = new SoftwareSerial(13,14);
//        nextion = new SoftwareSerial(Plugin_117_RXpin , Plugin_117_TXpin);
      }

      Serial.print("pin: ");
      Serial.println(Settings.TaskDevicePin1[event->TaskIndex]);
      Serial.println(Settings.TaskDevicePin2[event->TaskIndex]);
      Serial.println(Plugin_117_RXpin);
      Serial.println(Plugin_117_TXpin);

      nextion->begin(9600);

      success = true;
      break;
    }

    case PLUGIN_READ: {
        char deviceTemplate[8][64];
        LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));

        for (byte x = 0; x < 8; x++) {
          String tmpString = deviceTemplate[x];
          if (tmpString.length()) {
            String newString = parseTemplate(tmpString, 0);
            Serial.println(newString);

            sendCommand(newString.c_str());
            }
        }
        success = false;
        break;
      }


    case PLUGIN_WRITE: {
      String tmpString = string;
      int argIndex = tmpString.indexOf(',');
      if (argIndex)
        tmpString = tmpString.substring(0, argIndex);
      if (tmpString.equalsIgnoreCase(F("NEXTION"))) {
        argIndex = string.indexOf(',');
        tmpString = string.substring(argIndex + 1);

        sendCommand(tmpString.c_str());

        Serial.println(tmpString);
        success = true;
      }
      break;
    }
  }
  return success;
}




void Plugin_117_displayOn() {
}

void Plugin_117_displayOff() {
  
}

void sendCommand(const char *cmd) {
  nextion->print(cmd);
  nextion->write(0xff);
  nextion->write(0xff);
  nextion->write(0xff);
}

Jeff
Normal user
Posts: 26
Joined: 18 Nov 2016, 18:35

Re: Nextion display plugin

#96 Post by Jeff » 16 Jan 2017, 23:15

With the advice of @majklovec page 4 I managed to understand how to send commands to domoticz.
It's simple.
1) Try to make a button in the Nextion and check on "Touch release event" - "Send component id"
See the event sent
I create a button, when i push in the logs

Code: Select all

2726562 : Nextion : code: 
2726563 : EVENT: NEXTION#code=6.00
2726566 : EVENT: NEXTION#=0.00
2726569 : EVENT: NEXTION#=0.00
2726571 : EVENT: NEXTION#=0.00
In a rule

Code: Select all

on NEXTION#code=6.00 do
sendtohttp 192.168.1.19,8080,/json.htm?param=switchlight&type=command&idx=52&switchcmd=On
endon
log :

Code: Select all

2765418 : EVENT: NEXTION#code=6.00
2765421 : ACT : sendtohttp 192.168.1.19,8080,/json.htm?param=switchlight&type=command&idx=52&switchcmd=On
2765479 : EVENT: NEXTION#=0.00
2765482 : EVENT: NEXTION#=0.00
2765484 : EVENT: NEXTION#=0.00
Domoticz log :

Code: Select all

2017-01-16 23:13:14.416 User: Admin initiated a switch command (52/Led buanderie/On)
I'm happy :mrgreen:
Last edited by Jeff on 17 Jan 2017, 22:40, edited 1 time in total.

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#97 Post by BertB » 17 Jan 2017, 12:23

Ah ... I am going to try that tonight

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#98 Post by BertB » 17 Jan 2017, 23:28

This works very well too.

marko67
Normal user
Posts: 7
Joined: 20 Jan 2017, 06:40

Re: Nextion display plugin

#99 Post by marko67 » 20 Jan 2017, 07:13

Hello
It is my First Time here. I use one Wemos with a 2,8" Nextion. I have found this Forum to handle it with espeasy.
I have install r147 rc08 yesterday. Everything ok by flash. Now when i Look in to the devices i dosn't finde Nextion display. What is wrong?
The second thing i'll not understand.... the Arduino code that is post here in these thread have i to install at the Wemos too??

I will use ESP and Nextion with Fhem.

Thanks for helping

Marko

BertB
Normal user
Posts: 1019
Joined: 25 Apr 2015, 14:39

Re: Nextion display plugin

#100 Post by BertB » 21 Jan 2017, 18:23

Hi Marko,
Yes, you have to copy the code in this thread into a file named _P117_Nextion.ino.
I use wordpad for that.
Save that file in the ESPEasy folder.
Start the Arduino IDE, complie and flash.

That should be it.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests