Betreff: Modul ESP32-4848S040

If doesn't fit into any other category ....
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Betreff: Modul ESP32-4848S040

Post by Electroguard »

Hi, I haven't been following the thread and don't know what's been going on ... but generally speaking, if things are not happening as expected, then make those things as visible as possible to make it easier to spot where and when the problem happens.

If 'bi1' is a numeric variable name which should be set to 0 or 1 depending on the incoming udp msg, then set it to something else at the start of the program so you can check its value in one of the 2 Variable windows in the Editor (see pic) after seeing an incoming udp msg in the wlog window.
That will help you to see what causes any change, and if the change is what you expect.

varcheck.jpg

Don't forget you can temporarily insert END into any of the responding subroutines to 'freeze' var values which can then still be checked in the Variable windows even after the script has stopped.
Likewise you can keep moving a temporary END to different parts of your program to pinpoint where your variables are starting to go wrong.

I've inserted some wlog lines into your code to show the sort of thing which might help.

goudp:
v$ = udp.read$ 'receive the UDP data
wlog "incoming udp msg = " + v$
If v$ = "Relais1=1" Then
wlog "Relais1=1"
vgaGui.SetValue bi1, 1
UDP.REPLY "Relais1 gesetzt"
ENDIF
If v$ = "Relais1=0" Then
wlog "Relais1=0"
UDP.REPLY "Relais1 rückgesetzt"
vgaGui.SetValue bi1, 0
ENDIF
wlog "bi1=" + str$(bi1)
return

My 'EasyNet' devices communicate with each other by checking incoming UDP msgs for "Target Instruction Data" messages.
It has got quite complex, but if something is not responding as expected it is still fairly easy to enable appropriate wlog lines to check if the msg was received, if it was correct, if it was recognised, and if the appropriate subroutine called, etc.

Code: [Local Link Removed for Guests]

udpRX:
RXmsg$ = udp.read$
'wlog rxmsg$
RXin$ = word$(udp.remote$,1,":") + " at " + time$ + " on " + date$ + " "
if nameserver = 1 then
'wlog "incoming",   udp.remote$, RXmsg$ 
 word.setparam netlist$, udp.remote$, RXmsg$ + " at " + time$ + " on " + date$ + chr$(13)
endif
target$ = ucase$(word$(RXmsg$,1))          'Target may be NodeName or GroupName or "ALL" or localIP address
this=0
if (target$=nodeIP$) OR (target$=localIP$) OR (target$=ucase$(nodename$)) OR (instr(ucase$(groupname$),target$)>0) OR (target$="ALL") then
 instruction$ = trim$(ucase$(word$(RXmsg$,2)))  'Instruction is second word of message
 getdata data$,RXmsg$," ",2      'extract any data that follows the instruction
 select case instruction$
 case "NETLIST"   : gosub netlist
 case "TIMESYNC"  : gosub timesync
 case "OUTSIDE"   : gosub outside
 case "OFF"       : gosub netOFF
 case "ON"        : gosub netON
 case "UP",  "+"  : gosub setu
 case "DOWN","-"  : gosub setd
 case "TOGGLE"    : gosub netToggle
 case "","?"      : gosub this
 case "RESTART"   : msg$="Remote reboot":gosub Restart
 case else     
  if word.find(ucase$(instructionslist$),instruction$)>0 then
   gosub instruction$
   if dbug=1 then wlog "been there("+instruction$+"), done that"
  else
    if dbug=1 then wlog "Instruction "+instruction$+" not recognised from "+RXin$'+"("+RXmsg$+")"
  endif
'  onerror skip
'  gosub instruction$
'  wlog "ouch"
 end select
endif   '(target$=)
refresh
return
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 1995
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 428 times
Been thanked: 1335 times
Contact:

Re: Betreff: Modul ESP32-4848S040

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Feb 11, 2024 6:42 pm Thanks,
if it's vacation: nice time.
Yes 😁
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

Re: Betreff: Modul ESP32-4848S040

Post by Helmut_number_one »

The Help website says at Scope of the variables:
Variables and arrays defined in the main code are global, therefore any variable is accessible from any part of the code after it has been previously defined there.

I did that once, but it doesn't help either, it should be according to this description...

I cannot define variables locally in the page subprogram....
Then I can't change things on all pages via UDP and keep them visible by browsing.

That reveals what I suspect
the variables for the room and its display page are not separated in memory. Once I've leafed through the 4 pages, they're immediately accessible 4 times.
When I set the relay1 for room1 via UDP command and I am in the display page for that room, I only set the relay1.
But if I'm on another ad page, then Relay1 from page 1 is switched, too, but also something from the page I'm currently on because the variable also applies there.
Another effect is that the variables from page 2 are not known to the module when the module starts, so the interpreter complains that the variables from page 2 (probably also 3,4) are not known.
And this is true even though the page variables have different names
that is ok, now.

I need to make the settable variables unique.
If I change the page they are not allowed to appear there.
I thought they were global because they had their own names, but they aren't.

UDP receive Code with wlog if i send a UDP cmd ::

Code: [Local Link Removed for Guests]

 
v$ = udp.read$ 'receive the UDP data
wlog "incoming udp msg = " + v$
If v$ = "Relais1=1" Then
vgaGui.SetValue room1_bi1, 1
wlog room1_bi1
wlog room1_bi2
wlog room1_bi3
wlog room1_bi4
wlog room1_bi5
wlog room1_bi6

wlog room2_bi1
wlog room2_bi2
wlog room2_bi3
wlog room3_bi1
wlog room3_bi2
wlog room3_bi3
wlog room4_bi1
wlog room4_bi2
wlog "room_lights"
wlog room1_light1
wlog room1_light2
wlog room1_light3
wlog room1_light4
wlog room2_light1
wlog room2_light2
wlog room2_light3
wlog room3_light1
wlog room3_light2
wlog room3_light3
wlog room4_light1
wlog room4_light2  
In Log window :

Code: [Local Link Removed for Guests]

 incoming udp msg = Relais1=1
5
6
7
8
9
10
5
6
7
6
7
8
5
6
room_lights
1
0
0
0
0
0
0
0
0
0
0
0 
How do I do it?
not to use the variable room1_bi1 but to change the button image?
From the entry:

Code: [Local Link Removed for Guests]

 room1_bi1   = vgagui.ButtonImage(140, 376, 48, 48, lampOn$, lampOff$, toggle)  
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Betreff: Modul ESP32-4848S040

Post by Electroguard »

How do I do it?
not to use the variable room1_bi1 but to change the button image?
From the entry:
room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOn$, lampOff$, toggle)
Try re-declaring the same button ID with the images reversed, ie:
room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOff$, lampOn$, toggle)
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

Re: Betreff: Modul ESP32-4848S040

Post by Helmut_number_one »

This doesn't change the problem with the switches in other windows, which are still switched via UDP command.
Everything else outside of UDP switching commands works without problems

But it's nice from you to think about it.
If variables were actually global and unique then I think it would work.
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Betreff: Modul ESP32-4848S040

Post by Electroguard »

I'm not sure what is the actual problem you are having, but I'm sure you can find a solution. Sometimes it is better to not even try fixing the existing large program for the moment, but instead to get just some minimum 'no-frills' functionality working how you want it, then you can go back to fix your original program after.

All the variables defined in the top part of the program before the WAIT instruction are global and available to all subroutines.
Any variables defined in subroutines are only locally available to that subroutine.
Events are not variables, so buttons are not variables, they are only event triggers which can be used to change variables.

The vga.gui button is just a touch event, which can be likened to a web page button click event.
Both events branch to a specified subroutine to carry out whatever instructions are there.
Likewise an incoming UDP msg branches to a specified subroutine to carry out whatever instructions are there.

Let's say we have a lamp controlled by a relay RLY1 which is toggled in a subroutine called Toggle1
Toggle1:
if pin(RLY1) = 0 then
pin(RLY1) = 1
else
pin(RLY1) = 0
endif
return


By branching 'on event' to that same subroutine, the RLY1 lamp can be toggled using the touchscreen, or the web page button, or by UDP msg.

Whatever method is used to toggle RLY1 will probably want some feedback of the status made available to all event trigger methods.
In the case of the web button the background colour can be changed between red or green depending on RLY1 status.
In the case of trigger by UDP msg it could send a UDP broadcast of RLY1 status to any interested listening devices.
In the case of VGA touchscreen it should change the gui button image.
So it is just a matter of including all 3 feedbacks into the same event subroutine...
Toggle1:
if pin(RLY1) = 0 then
pin(RLY1) = 1
css cssid$("lamp","background:red;")
udp.write netip$ + "255", udpport, "RLY1 is ON"
room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOn$, lampOff$, toggle)
else
pin(RLY1) = 0
css cssid$("lamp","background:green;")
udp.write netip$ + "255", udpport, "RLY1 is OFF"
room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOff$, lampOn$, toggle)
endif
return

In this way you can make any of your different types of events trigger the same actions and give whatever different feedback indications you want.
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

Re: Betreff: Modul ESP32-4848S040

Post by Helmut_number_one »

That's right, but ;-)
Refute this theory for me:
Then I realize that it makes no sense to set the variable "room1_bi1 = 0" globally in the setup loop if this variable is in the subprogram with the statement " room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOn$, lampOff$, toggle) " is made a local variable and assigned a fixed value.

These variables before (for example) vgagui.ButtonImage get continued numbers inscribed by the interpreter.
So I can't use them as global variables
Try it.
Edit: my Firmware is Annex32-S3 CAN DMT VGA HID 1.52.1 qio opi LFS
Wiederlegen Sie mir diese These:
Dann erkenne ich, dass es keinen Sinn macht in der Setupschleife die Variable "room1_bi1 = 0" global zu setzen, wenn diese Variable in dem Unterprogramm mit der Anweisung " room1_bi1 = vgagui.ButtonImage(140, 376, 48, 48, lampOn$, lampOff$, toggle) " zu einer lokalen Variable und zu einem festen Wert gesetzt wird.

Diese Variablen vor (zum Beispiel ) vgagui.ButtonImage erhalten von dem Interpreter fortlaufen Zahlen eingeschrieben.
Ich kann sie also als Globale Variablen so nicht verwenden
Probieren Sie es aus
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Betreff: Modul ESP32-4848S040

Post by Electroguard »

So that is probably the cause of your problem then... you are using the same name for a global variable that you are later using as a gui element id.
If you have a wife called Freda, you cannot also name your dog and children Freda without causing confusion.
The gui items are not variables, they are gui element identifiers.
So when that gui element branches on event to the associated subroutine to handle the event, it needs to toggle a global variable of a name that is different to the gui element ID which called the subroutine, else it can get confused.
If the rest of the program is working correctly, I suggest you rename your existing gui element identifiers by eg: adding a letter to them to differentiate them from the variables which those gui events need to change.


Edit. Also, you should be aware that (as you have noticed) Annex assigns its own sequential element numbering to keep track of your chosen gui element identifiers. And I discovered some years ago that it was not possible to use my gui items in an array because the gui element indexing caused confusion with the array indexing.


Edit2. If I remember correctly, I was also unable to re-define an existing gui element, because it kept simply defining another new gui element but with the same name and the next unused sequential element ID number, eventually crashing after using up all available resource - so I don't know if you will even be able to successfully redefine your touch button gui's to swap their images... but that was sveral years and several versions ago, long before vga capability.
Helmut_number_one
Posts: 93
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 36 times
Been thanked: 8 times

Re: Betreff: Modul ESP32-4848S040

Post by Helmut_number_one »

global variable that you are later using as a gui element id.
That's the mistake, but where could I have read something like that?
Variables are also mentioned in the help page.
I don't know about other basic interpreter.
Ev. It would be good to specifically point out that the preceding "variable" cannot be used if it occurs in a subprogram.

You helped me a lot, thank you for that.

Here in Helpfile:
For example, defining a textline with:
TXT1 = GUI.Textline(10, 10, 100, 20, "Hello World!"
The variable txt1 will contain a handler permitting to modify the properties of the textline; for example the following line :
GUI.SetText TXT1, "Text changed!"
Will change the text of the object previously defined.
The term Element ID is much better.
In my opinion it would be better to use this story as a usable variable. Apparently you wanted to use it that way.

I hope that Francesco also has several floors or rooms that he would like to browse through and that he has another option like I do to change data in the display without the page currently being on the display.
Tuya Display can do this, other TFT buttons can too, with Zigbee, MQTT or other ways.

There will be a reason that I don't recognize.
Last edited by Helmut_number_one on Wed Feb 14, 2024 3:40 pm, edited 1 time in total.
User avatar
Electroguard
Posts: 855
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 273 times
Been thanked: 321 times

Re: Betreff: Modul ESP32-4848S040

Post by Electroguard »

Francesco has created a solo masterpiece in Annex, which he keeps evolving and improving.
I much prefer he spend his precious time creating terrific new innovations like VGA and USB OTG control, rather than waste it improving the already excellent documentation. So I enjoy what Annex is capable of, and what I am able to achieve with it, rather than expect it to be flawless.
I have no doubt you are creating something you will be proud of, and I am happy to have helped you progress with it.
Post Reply