Many thanks! Andy.
![Erg Blij :D](./images/smilies/icon_e_biggrin.gif)
Moderators: grovkillen, Stuntteam, TD-er
Less fun?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/
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
Code: Select all
if devicechanged['PZEM'] then
--print(devicechanged['PZEM'])
power,total = otherdevices_svalues['PZEM']:match("([^;]+);([^;]+)")
nextion("tpower.val="..power,"")
end
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
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()
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);
}
Do you also get this error I mentioned above?ledfreak3d wrote:yep plugin works fine
now to see how we can get something usefull on there
Code: Select all
print "sendTo 2,event,givemesomewater"
Code: Select all
va0.txt=va0.txt+"g"
print va0.txt
Code: Select all
cov va0.txt,j0.val,0
Code: Select all
On UNIT01#TEMPERATURE do
NEXTION,z0.val=[UNIT01#TEMPERATURE]
endon
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);
}
I still do not understand how it works.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)
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
print "sendTo 2,event,givemesomewater"
For converting numeric values to string use Nextion function cov:Code: Select all
va0.txt=va0.txt+"g" print va0.txt
So this way you are able to control actuators from Nextion.Code: Select all
cov va0.txt,j0.val,0
What ESP board are you using in the photo?ledfreak3d wrote:Plugin seems to work fine
now trying to see what variables work
see picture attached
Awesome. Can you suggest a source? I'd love to try some of these.ledfreak3d wrote:Its a replica of scargils esp board had some made in black very handy for the nextions and any esp project
I can solder, no issue there I just don't have the time these days. Is a populated board available?ledfreak3d wrote:Hey Depends if you want bare boards or
boards that have been populated
Users browsing this forum: Ahrefs [Bot] and 25 guests