Start a new topic

question about thsp , set and release function

 hi


1-

i set thsp=300 to switch off the display after 300sec on my arduino

but  how to switch off this function thsp ?

i have a slider on my config page where i can change the time this work fine.

image


2-my arduino update a lot of values and text on the display ,but when this part of updating is running i can`t receive touche events

how can i solve this probleme i need to update data and i need to know when a bp is pressed at same time?

image


this is for an house automation

i use :

arduino mega with 7" display to show stats (i get this stats from mysql server)

other

arduino mega with 16 relays card, 6 analoge inputs , 4 digital inputs and 12 pwm outs (send stats to mysql server)

image


i hope you can help me with this 2 problems


@ attachment i put 2 arduino sketch and the php file to send and catch data


php
php
ino
(20.8 KB)
ino

the missing hmi file

HMI
(9.09 MB)

1- i set thsp=300 to switch off the display after 300sec on my arduino but  how to switch off this function thsp ? i have a slider on my config page where i can change the time this work fine.


The Nextion Instruction Set includes the thsp System Variable.

https://www.itead.cc/wiki/Nextion_Instruction_Set#Nextion_HMI:_System_Variables_List


But reading its description states in the Nextion Instruction Set:  

If no touch operation, it will auto enter into sleep time (unit: second, minimum 3, maximum 65,535, power-on default 0), thsp=30(No touch operation within 30 seconds, it will auto enter into sleep mode), thsp=0(invalid).


So it would seem clear, that only reset (rest command) will return thsp to 0.
This is a design decision to either use or not use - but not both.

Still it is the users decision.


At 300 seconds or 5 minutes, I think it is clear the user has indeed completed their tasks by the time the Nextion device enters sleep mode.  That is 300 seconds without any touches, then sleep.  In 300 seconds, I have finished my coffee, left for work and am more than 1/2 way to my office.  (Okay so I work in a home office - but that's not the point).  In a real world situation, sleep in 300 seconds is more than enough - and saves well on the power bill.


2-my arduino update a lot of values and text on the display ,but when this part of updating is running i can`t receive touche events how can i solve this probleme i need to update data and i need to know when a bp is pressed at same time?


The Nextion is classed as a TTL device, not bidirectional full duplex.


Your sketches dealing with the Nextion device need to:

1) prioritize receive before send.

2) and question why you need to update so much data in single shot.

There are a couple of approaches that can be taken


Implement a Nextion user must wait state.


Disable touch while the update is in progress

Inform the user on the screen that the update is occurring

Inform user can not make changes until update is complete

.. perform updates

Remove user wait state once update is complete

Restore touch when update is completed


Decrease the time needed per update


At 9600 baud, this is 960 chars of data per second.

At 115200 baud this is 11520 chars of data per second


The easiest of these is increasing baud where it can be done

- this reduces the time needed to receive the update data


The one with a bit more effort is to shadow the data and

only update the data that has been changed.


An example is a date and time

 - most often it is only the seconds that has changed

   - yet too many users push the whole date and time every time.


When you design to fetch pages from the Internet

- expect delays - your Arduino is sequential processing.


But, I am certainly not debugging 1000+ lines of incomplete code.

- for the future, please limit your picture sizes to something reasonable

I may have 5760 x 1920 for my display

but few people are going to bother to look when your post is too large

and done in a dump and fix it for me fashion




Example using your code as a base for the example


RELAY_TXT_5_1.setText(r_txt_5_1);


Your reloader function will run this line every time reloader is called for page 1


However, as this is declared in the .ino as a char [5] then
- t4 on relay page can be set text-maxl to 4 and .sta as global
this will allow Nextion side recall of its last/current value

In the global scope of the Arduino sketch
- an array can be created, one bit or one byte for each variable

In the readReponseContent
 - before you issue strcpy and lose your old values
   a) check if root["r5"] is equal to r_txt_5_1
   b) set bit or byte in your array accordingly
        this will be your flag if it needs to be updated or not
   c) then do strcpy

Finally, in reloader case page 1
   if bit or byte in array for r_txt_5_1 states new incoming value
   a) RELAY_TXT_5_1.setText(r_txt_5_1);
   b) clear bit or byte once updated

Likewise for your series of NAME_TXT_x_x
- highly doubtful these dynamically change once received.

This methodology will reduce a high amount of unnecessary traffic.
Reduced traffic decreased time to update, increased response time

I would also question your main loop.
As Arduino is sequential processing and not multi core multi threaded each request you make in your main loop should be quick and tidy. The timing of these is extremely important

So just like cutting the time down to the Nextion so only necessary data ties up the rx/tx, if you want to have a responsive system you will need to program your network side to also have small chunks out bound for small chunks inbound

The reason you can't receive a button response from the Nextion is because loop is stuck for too long either in the phrase==0 section or in the httpRequest section.  Otherwise your loop would have been in NexLoop and your button response would have been received and triggered your code for it.

Put a timer around these three segments and catch via your serial debug, and you will see where all your time is disappearing to. Again reduce what needs to be sent with shorter meaningful debug information.  Set serial debug as high as it reliably allows - as it too steals your clock cycles in sequential processing.

Limit what you send over debug to the sections you are debugging.  A common mistake to debug all at once, debug with purpose or it too will become part of your problem.
i solve the problem i set the baud = 57600 into display
and the NexHardware.cpp  to baud=57600
now the serial port work faster and i catch my events

i know that the code is not perfect is only version 0.2


THX for help

Think in smaller quick acting chunk that process rapidly from the start

 - you will avoid many more issues down the road.

I have a more basic question. I want the display to goto sleep and dim way down after no touch activity. So if I understand this I use thsp=30 and the display goes to sleep in 30 seconds. 


Where do I put that command ? 

Does the screen automatically dim when the thsp is active?


I am not as concerned about the sleep mode I just want the display to dim way back and then by touching the screen it with brighten up again.


I looked at the dim command but I don't see anything there that allows me to automatically dim after a preset time. So maybe by using sleep it will do they dimming?


thanks

Jim




Jim


First it does not matter where the command is placed

- it could be put in page0 Preinitialization Event

- it could be sent over serial

- it could be put in a button release

Once thsp is set to non-zero value it cannot be reset to 0 unless Nextion is reset


In essence think of the thsp as a countdown timer (say we set to 30)

- every second where there is no touch, decreases a second

- every touch that happens, resets this back up to 30.


There is no dim in sleep.  The display is then off.

A touch will bring it back to the dim level it was before sleep.


The dim command will not do anything after an amount of time

- the dim command sets the level immediately on processing it.


There is no harm is testing thsp. 

Once you reset your Nextion,  thsp will be back to power on default of 0

Login or Signup to post a comment