Page 1 of 12

Nextion display plugin

Posted: 28 Apr 2016, 17:10
by Allycat1972
Hi guys. Great work as always. I want to add a Nextion touch screen to display Central Heating controls on my ESP, however it sends / receives commands over serial communications. Is there any plan to extend the serial commands to include GPIO control / state, etc? Or can someone provide an additional device plugin to communicate with a Nextion display?

Many thanks! Andy. :D

Re: Nextion display plugin

Posted: 10 May 2016, 08:21
by HarpieC
Highly apreciate! As these Displays comes with their own mcu on board the esp part should be very lightweight!
First a bridge between mqtt and the display would be nice.
Chris

Re: Nextion display plugin

Posted: 04 Aug 2016, 12:16
by Allycat1972
Can I bump this because I would really like to use ESPEasy instead of another software.

Is there an existing addon which can send / receive serial data and process commands like GPIO/12/1, etc

Re: Nextion display plugin

Posted: 23 Oct 2016, 13:33
by ledfreak3d
this would be a awesome addition
I can help with testing if needed
would be awesome for simple control and status readout

Re: Nextion display plugin

Posted: 23 Oct 2016, 18:14
by DonJuanito
Hi. Have a look at this tread: http://www.esp8266.nu/forum/viewtopic.p ... 2net#p9941.

The idea with a Nextion display should be to have a device which can be read from or written to. These read/write would have to be translated to the ESP serial port which is connected to the Nextion display.
It should work...
I don't have time to play with that now, so please, if you succeed, can you post your results? It would be appreciated...

Re: Nextion display plugin

Posted: 02 Nov 2016, 17:33
by Allycat1972
Thanks, but that only seems to read the serial data. Am I missing something, or is there already a possibility to send serial data? :?:

Re: Nextion display plugin

Posted: 02 Nov 2016, 18:02
by BertB
Ser2Net allows for bi-directional communication. You can for instance use it to get serial data from RFLINK gateway into Domoticz, but it requires a client (telnet?) that can read them. Domoticz has a RFLINK gateway with LAN interface module to do that.
Since the Nextion display can act both as an input device (touch screen buttons) as well as an output device with a special protocol, and so far there is no Domoticz module, some crafting on the sofware is needed.

Re: Nextion display plugin

Posted: 02 Nov 2016, 19:32
by BertB

Re: Nextion display plugin

Posted: 02 Nov 2016, 19:49
by ledfreak3d
yes I have those boards on scargils site
had 10 of them made
its not realy hard to send commands to nextion
but it would need a standard gui
ive changed the original nextion library so it supports software serial on any posst on the esp8266

Re: Nextion display plugin

Posted: 02 Nov 2016, 20:37
by BertB
Right. Now we need some hero to put it all together. I would like to have a plugin that can read data in my Domoticz and present it on the screen and vice versa, transfers button pushes to actions on Domoticz. Stricktly spoken, it is not a true ESPEasy function.

Re: Nextion display plugin

Posted: 03 Nov 2016, 00:30
by kr0815
Maybe OffTopic, but why don´t you use a cheap android phone instead a nextion display, price is not much higher, you get it incl. a housing, resolution is better.

I have one running since almost 2 years, using that software: http://netio.davideickhoff.de/de/

Re: Nextion display plugin

Posted: 03 Nov 2016, 23:42
by BertB
kr0815 wrote:Maybe OffTopic, but why don´t you use a cheap android phone instead a nextion display, price is not much higher, you get it incl. a housing, resolution is better.

I have one running since almost 2 years, using that software: http://netio.davideickhoff.de/de/
Less fun? :D

Re: Nextion display plugin

Posted: 04 Nov 2016, 10:05
by ledfreak3d
true lol

the big question is what kind of info do you want to display on the nextion screen

I would say atleast

the wifI SSID
the ip addres
system time
maybe system resources
sensors that are active

Re: Nextion display plugin

Posted: 04 Nov 2016, 12:34
by BertB
Nextion works with components that can be addressed and written to. Example: a text Block named t0 with a text attribute. So, if you enhance oled plugin and swap i2c for serial, or softserial, and add Fields for attribute names, you are on a possible track. At least, that is what I am trying, but I am not a skilled programmeren.
To get An impression try the the Nextion ide.

Re: Nextion display plugin

Posted: 04 Nov 2016, 13:03
by ledfreak3d
Yep indeed a own a couple so can test if needed
but would have to agree on a gui layout first

Re: Nextion display plugin

Posted: 05 Nov 2016, 23:45
by BertB
Something like this?

Device:
?
Name:
Delay:
Serial Tx Softserial would be nice, otherwise standard serial port.
Serial Rx
Baud Rate: Actually this is always 9600
Data bits:
Page Label IDX Variable
Line 1 : : : :
Line 2 : : : :
Line 3 : : : :
Line 4 : : : :
Line 5 : : : :
Line 6 : : : :
Line 7 : : : :
Line 8 : : : :
Display button:
Display Timeout:

Page represents the page number on the display. 0,1,2, ...
Label represents the name of an object on a page number on the display. t0 etc
IDX represents the device in Domoticz where information can be found.
Variable can hold local variable like Lux: [E7LUX#Lux#R] Lux or [clock#time]

Re: Nextion display plugin

Posted: 06 Nov 2016, 15:45
by ledfreak3d
yep I think something like that would be fine

Re: Nextion display plugin

Posted: 06 Nov 2016, 15:58
by Allycat1972
Hi Everyone.

Really pleased to see this topic getting some hits. As BertB says the Nextion is programmable and you set buttons to do things like send a string to the serial port. It also receives data and changes values / image states, etc. to make the display seem interactive.

Basically what we need is the ESP to receive the data from the serial port and send it to the MQTT server (topic and values can be programmed in the Nextion) The ESP also needs to receive instructions from the MQTT server and send them to the serial port.

On the Nextion I have a value called item called 'TEMP'. You change the value shown on the Nextion by sending an instruction 'TEMP.val=22'
I also have a button on the Nextion called 'FAN'. When it's pressed the Nextion can send an instruction 'publish fanbutton, on'. You can program it to send anything really and it can even do basic if..then..else stuff.

The ESPEasy software has everything, except the serial to MQTT.

Again, great work.

Re: Nextion display plugin

Posted: 06 Nov 2016, 21:05
by ayasystems
I'm using Ser2Net to controll my nextion.
Cwh97MJWEAAuwwg.jpg
Cwh97MJWEAAuwwg.jpg (111.07 KiB) Viewed 324337 times
Domoticz send data to ESP using a python script.

Works really fine!!!

Re: Nextion display plugin

Posted: 06 Nov 2016, 21:16
by ledfreak3d
that looks very nice
would you we willing to provide some files and info on how to do this
then we can build from there
the nextions are realy awesome lots we can do with them

Re: Nextion display plugin

Posted: 06 Nov 2016, 21:41
by BertB
Looks great. How did you do it?

Re: Nextion display plugin

Posted: 06 Nov 2016, 21:58
by BertB
I made quick and probably very dirty combination of ser2net and OLED plugin.
I can now send system variables to the display, using strings like :page0.t0.txt="%systime%" and page0.g0.txt="%ip%"

Re: Nextion display plugin

Posted: 06 Nov 2016, 22:20
by ayasystems
ESP8266 as Ser2Net server...

Domoticz call to os command with the new data from lua:


Code: Select all


local function nextion(cmd,value)
   if(value=="") then
     comando = "/home/odroid/scripts/sentSer2Net.py "..cmd
   else
     comando = "/home/odroid/scripts/sentSer2Net.py "..cmd.." "..value
   end
   --print(comando)
   os.execute(comando)
end

Then my device call the function

Example my wh meter (into lua script

Code: Select all

if devicechanged['PZEM'] then
    --print(devicechanged['PZEM'])
    power,total = otherdevices_svalues['PZEM']:match("([^;]+);([^;]+)")
    nextion("tpower.val="..power,"")
end
Example my room themperature sensor

Code: Select all

if devicechanged['EntradaTemp'] then
--    print('EntradaTemp')
    d1,d2,d3=otherdevices_svalues['EntradaTemp']:match("([^;]+);([^;]+);([^]+);([^;]+)")
    nextion("tentrada.txt",d1)
    nextion("hentrada.txt",d2)
end

the python script:

Code: Select all

#!/usr/bin/env python
import socket
import sys

TCP_IP = '192.168.3.221'#ESP8266 IP
TCP_PORT = 8080#SER2NET PORT
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.connect((TCP_IP, TCP_PORT))
except socket.error, msg:
    sys.exit(1)
COMMAND = sys.argv[1]
if len(sys.argv) > 2:
    VALUE   = sys.argv[2]
    s.send(COMMAND)
    s.send("=\"")
    s.send(VALUE)
    s.send("\"")
    s.send(b'\xFF\xFF\xFF')
    s.close()
else:
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))
    s.send(COMMAND)
    s.send(b'\xFF\xFF\xFF')
    s.close()
Let my know if you have any dubt

Regards!

Re: Nextion display plugin

Posted: 06 Nov 2016, 22:26
by BertB
Thank you.
I will study that, but I admit that I do not at all understand that lua gibberish ;)

Re: Nextion display plugin

Posted: 09 Nov 2016, 02:40
by majklovec
Dirty, easy, working.

Enjoy

Code: Select all

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

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

#define PLUGIN_104
#define PLUGIN_ID_104 104
#define PLUGIN_NAME_104 "Display: Nextion"
#define PLUGIN_VALUENAME1_104 "code"
unsigned long Plugin_104_code = 0;
SoftwareSerial *nextion;

boolean Plugin_104(byte function, struct EventStruct *event, String &string) {
  boolean success = false;

  switch (function) {

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

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

      break;
    }

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

    case PLUGIN_GET_DEVICEVALUENAMES: {
      strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0],
               PSTR(PLUGIN_VALUENAME1_104));
      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_104_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;
            while (nextion->available() > 0) {
              __buffer[i++] = nextion->read();
              Serial.write((char)__buffer[i]);
            }
            Serial.println();
            __buffer[i] = 0x00;

            String log = F("Nextion : send command: ");
            log += __buffer;
            addLog(LOG_LEVEL_INFO, log);

            ExecuteCommand(VALUE_SOURCE_SYSTEM, __buffer);
          }
        }
      }

      success = true;
      break;
    }

    case PLUGIN_WEBFORM_LOAD: {
      char tmpString[128];
      sprintf_P(tmpString, PSTR("<TR><TD>RX:<TD><input type='text' "
                                "name='taskdevicepin1' value='%u'>"),
                Settings.TaskDevicePin1[event->TaskIndex]);
      string += tmpString;
      sprintf_P(tmpString, PSTR("<TR><TD>TX:<TD><input type='text' "
                                "name='taskdevicepin2' value='%u'>"),
                Settings.TaskDevicePin2[event->TaskIndex]);
      string += tmpString;
      success = true;
      break;
    }

    case PLUGIN_INIT: {
      LoadTaskSettings(event->TaskIndex);
      if (!nextion) {
        nextion = new SoftwareSerial(Settings.TaskDevicePin1[event->TaskIndex],
                                     Settings.TaskDevicePin2[event->TaskIndex]);
      }

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

      nextion->begin(9600);

      success = true;
      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 sendCommand(const char *cmd) {
  nextion->print(cmd);
  nextion->write(0xff);
  nextion->write(0xff);
  nextion->write(0xff);
}


Re: Nextion display plugin

Posted: 09 Nov 2016, 08:30
by ledfreak3d
ill give it a go when I am home tonight se what we an do / improve on it

thanks for the work done majklove

Re: Nextion display plugin

Posted: 09 Nov 2016, 11:02
by BertB
@majklovec. Looks great and it compiles well and even seems to live, but what does it exactly do?

With serial log level 4 I get:
ADC : Analog value: 0
EVENT: Anain#Analog=0.00
HTTP : connecting to 192.168.0.243 using port 8080
/json.htm?type=command&param=udevice&idx=1&svalue=0.00
HTTP/1.1 200 OK

HTTP : Success
Content-Length: 24

Content-Type: application/json;charset=UTF-8

Cache-Control: no-cache

Pragma: no-cache

Access-Control-Allow-Origin: *



{
"status" : "ERR"
}
HTTP : closing connection
EVENT: Clock#Time=Wed,09:54
UDP : 18:fe:34:f2:01:4e,192.168.0.70,10
UDP : 18:fe:34:f2:01:7b,192.168.0.69,9
UDP : 18:fe:34:9e:74:46,192.168.0.61,1

Re: Nextion display plugin

Posted: 09 Nov 2016, 11:04
by BertB
When I create a button in Domoticz and I put http://192.168.0.72/control?cmd=NEXTION,t0.txt="hoi" in the OnAction, I get the string in the display in textbox t0.
And when a send http://192.168.0.72/control?cmd=NEXTION,z0.val=10, I see a gauge item move to value 10
Great!

Re: Nextion display plugin

Posted: 09 Nov 2016, 19:38
by ledfreak3d
yep plugin works fine
now to see how we can get something usefull on there ;)

Re: Nextion display plugin

Posted: 09 Nov 2016, 20:55
by BertB
ledfreak3d wrote:yep plugin works fine
now to see how we can get something usefull on there ;)
Do you also get this error I mentioned above?

Re: Nextion display plugin

Posted: 09 Nov 2016, 21:17
by ledfreak3d
nope no error
ive created a quick hmi file for testing and I can send value's and text to the corresponding test and value fields

Re: Nextion display plugin

Posted: 09 Nov 2016, 21:23
by majklovec
Bert, yeah that's it.

It works even the other way around. 2 options are available:

1) Try to make a button in the Nextion and check on "Touch release event" - "Send component id"
See the event sent.

2) Or do not check "Send component id" and use printto send whatever event back to ESPEasy.

Only send command is supported (actually all starting with 's' as seen in the code)

Code: Select all

print "sendTo 2,event,givemesomewater"
Via print you are able to send even the variables (choose String type), for example - RGB sliders, by concating them and printing aftewhile.

Code: Select all

va0.txt=va0.txt+"g"
print va0.txt
For converting numeric values to string use Nextion function cov:

Code: Select all

cov va0.txt,j0.val,0
So this way you are able to control actuators from Nextion.

Re: Nextion display plugin

Posted: 09 Nov 2016, 21:54
by ledfreak3d
thanks for the explanation majklovec

any idea how we can display esp easy stats like ip addres system time
or a sensor value from espeasy ?

is there a way to assign a virtual button on the nextion to a virtual / dummy switch on esp easy or in domoticz itself

Re: Nextion display plugin

Posted: 09 Nov 2016, 22:03
by majklovec
@ledfreak3d

Just use rules and send the command to nextion:

Code: Select all

On UNIT01#TEMPERATURE do
     NEXTION,z0.val=[UNIT01#TEMPERATURE]
endon
I believe the same way %internal variables% can be sent.

I don't know domoticz, so I can't serve.

Re: Nextion display plugin

Posted: 10 Nov 2016, 08:36
by ledfreak3d
ahh yea that makes sense

ill see if I can build a test gui today and send over some data to the display that are usefull
my mane intererest would be sending data to domoticz to get it to do stuff
but I am sure we will find a way for that to

will post the results

Re: Nextion display plugin

Posted: 10 Nov 2016, 09:07
by BertB
I would also like te possibility to display data like Oled Does.

Re: Nextion display plugin

Posted: 10 Nov 2016, 11:13
by ledfreak3d
humz been testing this morning via rules
but have not been able to get values displayed yet
can send command via http command line but the same command via rules does nothing

Re: Nextion display plugin

Posted: 10 Nov 2016, 11:41
by papperone
I'm goign to order a Nextion to experiment and probaly wall mounting it as GUI for my home automation.
I'm just puzzled which size to order, 3.5" and 4.2" seems ok size-wise but really expensive, specially if you go to enhanced version.
Which one you owns/use (size and normal or enhance) and what are your advise??

Re: Nextion display plugin

Posted: 10 Nov 2016, 11:56
by ledfreak3d
I own a 2.4 and a 3,5 inch the basic versions

work perfectly for most things

Re: Nextion display plugin

Posted: 10 Nov 2016, 12:28
by ayasystems
I think that tcp could not be the best way because if esp8266 is not alive it will raise a time out on each comunication and error...

The best way cloud be use udp to send the data to espeasy or use esp to read and parse json data

Re: Nextion display plugin

Posted: 11 Nov 2016, 08:15
by ledfreak3d
no results yet but working on it

Re: Nextion display plugin

Posted: 12 Nov 2016, 13:03
by BertB
I did some ehm pick and mix and drag an drop on the code from Majklovec and OLED plugin and now it reads up to 8 lines of text from the plugin.

Code: Select all

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

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

#define PLUGIN_104
#define PLUGIN_ID_104 104
#define PLUGIN_NAME_104 "Display: Nextion"
#define PLUGIN_VALUENAME1_104 "code"
unsigned long Plugin_104_code = 0;
SoftwareSerial *nextion;

boolean Plugin_104(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_104;

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

      break;
    }

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

    case PLUGIN_GET_DEVICEVALUENAMES: {
      strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0],
               PSTR(PLUGIN_VALUENAME1_104));
      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_104_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;
            while (nextion->available() > 0) {
              __buffer[i++] = nextion->read();
              Serial.write((char)__buffer[i]);
            }
            Serial.println();
            __buffer[i] = 0x00;

            String log = F("Nextion : send command: ");
            log += __buffer;
            addLog(LOG_LEVEL_INFO, log);

            ExecuteCommand(VALUE_SOURCE_SYSTEM, __buffer);
          }
        }
      }

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

      success = true;
      break;
    }

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


    case PLUGIN_WEBFORM_SAVE: {
      String plugin1 = WebServer.arg("plugin_104_timer");
      Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
      String plugin2 = WebServer.arg("plugin_104_rxwait");
      Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin2.toInt();
      String plugin3 = WebServer.arg("plugin_104_events");
      Settings.TaskDevicePluginConfig[event->TaskIndex][2] = plugin3.toInt();

      char deviceTemplate[8][64];
      for (byte varNr = 0; varNr < 8; varNr++) {
        char argc[25];
        String arg = F("Plugin_104_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];
      sprintf_P(tmpString, PSTR("<TR><TD>RX:<TD><input type='text' "
                                "name='taskdevicepin1' value='%u'>"),
                Settings.TaskDevicePin1[event->TaskIndex]);
      string += tmpString;
      sprintf_P(tmpString, PSTR("<TR><TD>TX:<TD><input type='text' "
                                "name='taskdevicepin2' value='%u'>"),
                Settings.TaskDevicePin2[event->TaskIndex]);
      string += tmpString;

      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_104_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_104_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 (!nextion) {
        nextion = new SoftwareSerial(Settings.TaskDevicePin1[event->TaskIndex],
                                     Settings.TaskDevicePin2[event->TaskIndex]);
      }

      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, 16);
            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_104_displayOn() {
}

void Plugin_104_displayOff() {
  
}

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

Re: Nextion display plugin

Posted: 12 Nov 2016, 13:08
by BertB
I also created a screen for the display itself.
setting up Nextion
setting up Nextion
Winscreen.png (54.22 KiB) Viewed 326937 times

Re: Nextion display plugin

Posted: 13 Nov 2016, 16:37
by BertB
majklovec wrote:Bert, yeah that's it.

It works even the other way around. 2 options are available:

1) Try to make a button in the Nextion and check on "Touch release event" - "Send component id"
See the event sent.

2) Or do not check "Send component id" and use printto send whatever event back to ESPEasy.

Only send command is supported (actually all starting with 's' as seen in the code)

Code: Select all

print "sendTo 2,event,givemesomewater"
Via print you are able to send even the variables (choose String type), for example - RGB sliders, by concating them and printing aftewhile.

Code: Select all

va0.txt=va0.txt+"g"
print va0.txt
For converting numeric values to string use Nextion function cov:

Code: Select all

cov va0.txt,j0.val,0
So this way you are able to control actuators from Nextion.
I still do not understand how it works.
I can use the Send comonent id checkbox, but makes the ESP to send a large number to the Domoticz device.
But how can I make the ESP to send for instance a switch command?
When I create a button on Nextion with the command print "SendToHTTP 192.168.0.243,8080,/json.htm?type=command&param=switchlight&idx=174&switchcmd=On" nothing happens and most of the time the string is corrupted.

Re: Nextion display plugin

Posted: 14 Nov 2016, 13:21
by ledfreak3d
Plugin seems to work fine
now trying to see what variables work
see picture attached

Re: Nextion display plugin

Posted: 17 Nov 2016, 04:10
by xbmcnut
ledfreak3d wrote:Plugin seems to work fine
now trying to see what variables work
see picture attached
What ESP board are you using in the photo?

Re: Nextion display plugin

Posted: 17 Nov 2016, 07:00
by ledfreak3d
Its a replica of scargils esp board had some made in black very handy for the nextions and any esp project

Re: Nextion display plugin

Posted: 17 Nov 2016, 07:52
by xbmcnut
ledfreak3d wrote:Its a replica of scargils esp board had some made in black very handy for the nextions and any esp project
Awesome. Can you suggest a source? I'd love to try some of these.

Re: Nextion display plugin

Posted: 17 Nov 2016, 08:20
by ledfreak3d
Hey Depends if you want bare boards or
boards that have been populated ;)

Re: Nextion display plugin

Posted: 17 Nov 2016, 08:25
by xbmcnut
ledfreak3d wrote:Hey Depends if you want bare boards or
boards that have been populated ;)
I can solder, no issue there I just don't have the time these days. Is a populated board available?