16/12 tasks ?

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
User avatar
uxhamby
Normal user
Posts: 101
Joined: 29 Dec 2016, 18:13
Location: Toronto Canada

16/12 tasks ?

#1 Post by uxhamby » 03 Feb 2021, 21:19

Suppose I want to use all 16 pins of an MCP23017 as inputs. Do I need 16 tasks, or am I missing something?

Assuming I am correct, how does one accomplish this, when only 12 tasks are offered in the pre-compiled .bin versions?

Thanks,

Brian H.

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#2 Post by Ath » 03 Feb 2021, 21:57

An ESP32 with ESPEasy offers 32 tasks, and already has more GPIO's by itself. Plus the CPU is much faster (240 MHz over 80 MHz), and dual-core, it is IMHO a way more desirable unit for many tasks. It's just that most ESP32 boards are larger then the Wemos D1 Mini form-factor, more like a NodeMCU, that may cause issues when trying to mount it in some tiny spaces. And it can be a bit more challenging to initially get the firmware on, but when using this Flashing the ESP32 manual it should be pretty easy. After that, updates can be installed OTA (Over the Air), via the web interface.
/Ton

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#3 Post by TD-er » 03 Feb 2021, 21:58

The GPIO commands (also for GPIO expanders) have been moved to be an internal command (documentation is in progress), so you don't need a task for all.

ESP32 does have 32 tasks and there is a possibility to make a (not officially) supported 24 tasks on the ESP8266.

The commands you can use are:
mcpgpio
mcpgpiotoggle
mcplongpulse
mcplongpulse_ms
mcppulse

Similar to the GPIO commands as described here:
https://espeasy.readthedocs.io/en/lates ... 0-typename

The port numbers for the mcp range from 1 ... 128
16 per I2C address, so you can enumerate the possible I2C addresses of the MCP23017
Each next address uses the next 16 pins in pin nr.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#4 Post by Smotek7 » 04 Feb 2021, 16:54

Coincidentally, I'm just considering whether it is possible to use 4 pcs MCP23017 with one ESP32.
If the commands are moved to an inertial command, does that mean I don't have to manually create devices but create text rules, (by multiplying CTRL + C, CTRL + V)?
Can I find an example somewhere?
Can it do 4x16 input or 4x16 output?

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#5 Post by TD-er » 04 Feb 2021, 17:56

Each pin should be possible to set as input or output and with the commands (and option to monitor) you can act on those GPIO pins in rules events.

I haven't used them, and the user that made those commands is working on the documentation (not yet finished)
I hope he can already give some examples here.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#6 Post by Smotek7 » 04 Feb 2021, 18:17

And can ESP32 4pcs MCP handle as input?
Can I tie it over?
So far I only have 2, 32 inputs.

As an output, just send the correct http command.

User avatar
uxhamby
Normal user
Posts: 101
Joined: 29 Dec 2016, 18:13
Location: Toronto Canada

Re: 16/12 tasks ?

#7 Post by uxhamby » 03 Mar 2021, 21:18

Ath wrote: 03 Feb 2021, 21:57 An ESP32 with ESPEasy offers 32 tasks, and already has more GPIO's by itself. Plus the CPU is much faster (240 MHz over 80 MHz), and dual-core, it is IMHO a way more desirable unit for many tasks. It's just that most ESP32 boards are larger then the Wemos D1 Mini form-factor, more like a NodeMCU, that may cause issues when trying to mount it in some tiny spaces. And it can be a bit more challenging to initially get the firmware on, but when using this Flashing the ESP32 manual it should be pretty easy. After that, updates can be installed OTA (Over the Air), via the web interface.
OK, I take your point although none of these tasks are ever going to see high traffic, as I am just monitoring slow moving phenomena like multiple doors and window open / close and HVAC air pressure status etc.

That said though, as it happens, I have an ESP32 D1 mini board at hand and am interested to try out ESPeasy, on an ESP32. FWIW, all my other ESP32's are runing MicroPython. MicroPython is an excellent platform but I am not a born programmer so my prowess in that realm, intriguing though it is, is modest, at best.

My available D1 Mini, is labelled as being "Model ESP32S" on the RF can. Which of the prefab binaries in the latest 'ESPEasy_ESP32_mega-20210223.zip', is most appropriate? I am favouring 'ESP_Easy_mega_20210223_normal_ESP32_4M316k.bin', but am unsure which might be optimal.

Thoughts or advice?

Thanks,

Brian H.

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#8 Post by TD-er » 03 Mar 2021, 23:08

Sounds like a good one to start.
Please read the readme, or the ReadTheDocs about flashing the ESP32 as it is slightly different from the ESP8266
Most importantly you should start with a "factory" one when flashing via serial (which is the first flash anyway).
Later updates via the web interface can be done with files without the "factory" in the name.

As you will not have ethernet on board, no need to use a build with "ETH" in the name.

The "normal" "testing" labels are the same as on ESP8266 and I only have 4M316k builds for ESP32 (4M flash, 316k SPIFFS)

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#9 Post by Smotek7 » 12 Mar 2021, 20:39

TD-er
My previous question.
Who can advise me an example of how to set more than 32 inputs with MCP23017?
Please, which user is working on it?

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#10 Post by TD-er » 12 Mar 2021, 20:46

User Stefano (giig1967g) has been working on the code for the GPIO expanders.
You can enable monitoring for a number of pins and act on the events triggered by the monitoring if a pin is triggered.
This can then be handled in the rules, so there is no practical limit on the number of GPIO pins other than what can be addressed through various GPIO expanders and the available resources in the ESP.
See: https://espeasy.readthedocs.io/en/lates ... al-mcpgpio

N.B. the "Range" commands are new and although they are now present in the git repository, they are not yet present in nightly builds.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#11 Post by Smotek7 » 12 Mar 2021, 21:21

It is enough to create a rule:
on System # Boot do
mcpModeRange, 1,48,1
MonitorRange, MCP, 0,48
endon

Although the GPIO range of MonitorRange is not sure if it is entered correctly.

Is Stefano following this thread?

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#12 Post by Smotek7 » 14 Jan 2022, 00:20

After a long time, I return to this problem.

Now I'm trying to send a command
http://192.168.1.195/control?cmd=mcpgpio,6,1

1. send
returned MCP: port # 6: set to -1
why set -1?

2. send
MCP returned: port # 6 is offline.
I use
ESP_Easy_mega_20211224_normal_ESP32_4M316k_ETH Dec 24 2021
mcp.JPG
mcp.JPG (17.8 KiB) Viewed 16444 times

Second question:
when I look at the documentation
https://espeasy.readthedocs.io/en/lates ... al-mcpgpio

command
MonitorRange, MCP, <MCPGPIO>
why <MCPGPIO>?
it shouldn't be right when it's range
MonitorRange, MCP, <MCPGPIO start pin>, <MCPGPIO end pin>

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#13 Post by TD-er » 14 Jan 2022, 09:10

Smotek7 wrote: 14 Jan 2022, 00:20 [...]

Second question:
when I look at the documentation
https://espeasy.readthedocs.io/en/lates ... al-mcpgpio

command
MonitorRange, MCP, <MCPGPIO>
why <MCPGPIO>?
it shouldn't be right when it's range
MonitorRange, MCP, <MCPGPIO start pin>, <MCPGPIO end pin>
Don't know an answer right now on the first question.
About the second question, Yep that's a "bug" in the documentation.
Just looked at the code and it indeed requires 2 numerical parameters for start pin and end pin (including the end pin, thus range of 1,2 means pin 1 and pin 2)

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#14 Post by Smotek7 » 14 Jan 2022, 10:57

1. was a micro short to PCB between SCL and SDA
(and I had used IO12 on SDA, ESP didn't start correctly)

2. I will test

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#15 Post by TD-er » 14 Jan 2022, 11:05

You really must take care on using GPIO-12 on ESP32
See: https://espeasy.readthedocs.io/en/lates ... e-on-esp32

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#16 Post by Smotek7 » 14 Jan 2022, 12:04

I didn't know that when I designed the PCB :(

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#17 Post by TD-er » 14 Jan 2022, 12:14

Smotek7 wrote: 14 Jan 2022, 12:04 I didn't know that when I designed the PCB :(
Just keep that page bookmarked, as it is one of the most frequently used pages of the docs.
(at least I link and use it very often ;) )

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#18 Post by Smotek7 » 14 Jan 2022, 22:04

it works for me command in rules

on System#Boot do
MonitorRange,MCP,1,64
MCPmodeRange,1,64,1
endon

then I have to write for each pin

on mcp#9 do
if [plugin#mcpgpio#pinstate#9]=1
SendToUDP 192.168.1.100,550,MCP9_1
endif
if [plugin#mcpgpio#pinstate#9]=0
SendToUDP 192.168.1.100,550,MCP9_0
endif
endon

Is there another way to make it easier?

I have created a "Driver"
Generic UDP
it works for me when I define mcp23017 in devices
can i use it in rules?

Any other ideas than not writing a 64x rule?

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#19 Post by Ath » 14 Jan 2022, 22:14

Smotek7 wrote: 14 Jan 2022, 22:04 it works for me command in rules

Code: Select all

on System#Boot do
 MonitorRange,MCP,1,64
 MCPmodeRange,1,64,1
endon
then I have to write for each pin

Code: Select all

on mcp#9 do
if [plugin#mcpgpio#pinstate#9]=1	
    SendToUDP 192.168.1.100,550,MCP9_1
 endif
if [plugin#mcpgpio#pinstate#9]=0	
    SendToUDP 192.168.1.100,550,MCP9_0
endif
endon
Is there another way to make it easier?

I have created a "Driver"
Generic UDP
it works for me when I define mcp23017 in devices
can i use it in rules?

Any other ideas than not writing a 64x rule?
You can simplify a bit I thing:

Code: Select all

on mcp#9 do
  SendToUDP 192.168.1.100,550,MCP9_[plugin#mcpgpio#pinstate#9]
endon
The replace will take place before the command is executed

And probably be further simplified to

Code: Select all

on mcp#9 do
  SendToUDP 192.168.1.100,550,MCP9_%eventvalue1%
endon
/Ton

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#20 Post by Smotek7 » 14 Jan 2022, 22:52

super
SendToUDP 192.168.1.100,550, MCP9_% eventvalue1%
it works

and how to use IP address and port with Controlers settings?
so that it does not have to be rewritten X times during the change.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#21 Post by Smotek7 » 15 Jan 2022, 20:40

I've solved it easily so far
I turned on syslog settings on IP and port.

And I found another problem, I need inversed logic on the inputs.
And remap HW imput to SW imput, input numbering.

If I learned to do a Custim build
@ TD-er can I create 64 task in devices?
Can tasks be created directly in the build?
Or create them by copying config.dat if possible.

So that I can use the standard send controller and inversed logic functions.

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#22 Post by TD-er » 15 Jan 2022, 20:53

You could define TASKS_MAX in your Config.h file.
For ESP32, this is already set at 32.
Not sure what may fail if you set it at 64.

Just keep in mind that config.dat files highly depend on this value, so a settings file based on XX tasks will not work on a build made for YY tasks.
One thing that might fail is that you try to write beyond the end of the settings file.

To see how the settings file is layout, you can enter "meminfodetail" in the command field and then open the sysinfo page.
At the bottom, there will be a graphical representation of how it is layout in the settings file.
Maybe you have to crease the file size too, for the Settings file.
Each task needs 2k and on an ESP32 it is layout such that the TaskSettings and the CustomTaskSettings are starting at the 32k position.
Since the default settings file on ESP32 is 128k in size, I think you can use 48 tasks without any issues.
If you go above that, you may need to increase the file to 160k, but that may cause other issues on the relatively small SPIFFS file system.

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#23 Post by Ath » 16 Jan 2022, 13:10

Smotek7 wrote: 15 Jan 2022, 20:40 can I create 64 task in devices?
Why do you need that many tasks? I'm interested to hear arguments for that.
For monitoring a large number of GPIO pins, like PCA or MCP, there are the matching 'monitor' commands, and yes, it does add (quite) some rules to handle all that, but with some tweaking that should be manageable.
Having that number of tasks would warrant adding/enabling paging in the Devices tab, as the list would become quite long.

If 48 or 64 tasks aren't enough, there is also the 'sister-project' RPiEasy, that allows 255 tasks (AFAICS), and uses a more potent system, a Raspberry Pi.
/Ton

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#24 Post by Smotek7 » 16 Jan 2022, 19:40

I don't know where to start, but I'll try to clarify.

The module will be designed for connecting buttons to home automation.
At the moment I have a module of 100 inputs that I want to replace (it has complicated communication with the system)
I currently have 52 entries.
Therefore, I designed a HW board for 64 inputs, I dealt with the SW of 64 inputs.
I have made a PCB 64IN and 32OUT. I could have combined it, but currently I already have a PCB equipped with components.
That's why I'm trying, doriesit SW.

Thank you for your help.

I am currently issuing a solution:

A) It works via syslog UDP messages
but everything goes into the system, I can't set just some.
I can't fix inversed logic

B) code in rules, the harder I can do inversed logic
I guess it would get me into 3 rules
here I have a problem that in Sendtoudp I have to fill in the IP and port for each entry
If there was a possibility in Sendtoudp to set the controller number directly, this path would suit me
(something similar to Sendto 1, xxxx, but it only works with MQTT as I understand it)

C) learn custom build, and try to increase the number of tasks
, I have no idea what problems await me

Definitely not "Rpi" (also because I already have HW)

Summary
I have a HW PCB equipped with 4xmcp23017 .....
I want to activate 64 input, inversed logic in ESPeasy.
Set 1x generic UDP controller.

I would like to go on route B.
Is there a way to define a controller in Sendtoudp?
Is the IP and port in the controller some system variable that could be used in rules?
Or pass it through some variable?

Thanks again for your help

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#25 Post by TD-er » 16 Jan 2022, 20:08

Will there ever be the need for 2 keys be pressed at the same time?

I was thinking, we do have a few plugins (or was it only 1?) to support a keyboard matrix like those cheap AliExpress key pads.
Those work by putting a column or row high and then look at the GPIO connected to the other (row or column) to see if it is high too.
For 12 keys you only need 7 pins.
Using GPIO expanders it should be rather easy to create a larger matrix to read more keys in a matrix.
It is probably best to have it supported in a plugin, but I guess you could even make it work in rules by using the monitor command and some events even though that probably takes quite some effort to get it right.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#26 Post by Smotek7 » 16 Jan 2022, 21:46

It's not a keyboard matrix.
One button at a time 1 input.
The buttons are on the wall and each switches a 24V signal.
The PCB is at the input
optocopler for voltage isolation, followed by input mcp23017.
Yes I made it possible using command monitor (monitorrange and MCPmodeRange)
The problem is that I have to write for each button
SendToUDP 192.168.1.100,550, MCP9_% eventvalue1%
where IP is inserted.

If I want to invert the logic I have to write
on mcp # 9 to
if [plugin # mcpgpio # pinstate # 9] = 0
SendToUDP 192.168.1.100,550, MCP9_1
endif
if [plugin # mcpgpio # pinstate # 9] = 1
SendToUDP 192.168.1.100,550, MCP9_0
endif
endon

And this bothers me when I want to fix an IP or a port, I have to rewrite the IP 64 times in the first case, or 128 times in the 2nd case.

I need Sendtoudp to support the settings via the controller tab (I don't know if I'm describing correctly).
cont.JPG
cont.JPG (25.65 KiB) Viewed 16271 times
Maybe something is also undocumented.
I found
Sendtoudp needs to enter the IP
Sendto is for P2P (IP is not entered here, but unit)
Publish is for MQTT

Maybe something like
Sendtoudp% controlerIP%,% controlerPort%, <command> :D

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#27 Post by Ath » 16 Jan 2022, 21:57

TD-er wrote: 16 Jan 2022, 20:08 I was thinking, we do have a few plugins (or was it only 1?) to support a keyboard matrix like those cheap AliExpress key pads.
Those work by putting a column or row high and then look at the GPIO connected to the other (row or column) to see if it is high too.
For 12 keys you only need 7 pins.
Using GPIO expanders it should be rather easy to create a larger matrix to read more keys in a matrix.
It is probably best to have it supported in a plugin, but I guess you could even make it work in rules by using the monitor command and some events even though that probably takes quite some effort to get it right.
That's plugin 61, Keypad - PCF8574 / MCP23017, right? That's available in any of the TEST builds ;) You will get events with a keycode, and it is quite easy to implement. If you need to have them as on/off switches, for sending an on/off state to an external system, then you can use the "let" command, with an offset per task, to toggle a value, and then send it out via a generic event with a few arguments:

Code: Select all

on SendoutEvent do // %1 = port, %2 = value
  SendToUDP,192.168.1.100,550,MCP%eventvalue1%_%eventvalue2%
endon

on Keypad1#ScanCode do
  let,100+%eventvalue1%,![var#100+%eventvalue1%]
  asyncevent,SendOutEvent=100+%eventvalue1%,[var#100+%eventvalue1%] // MCP1xx_n
endon

on Keypad2#ScanCode do
  let,200+%eventvalue1%,![var#200+%eventvalue1%]
  asyncevent,SendOutEvent=200+%eventvalue1%,[var#200+%eventvalue1%] // MCP2xx_n
endon
// etc.
/Ton

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#28 Post by TD-er » 16 Jan 2022, 22:07

Code: Select all

on mcp#9 do
  SendToUDP 192.168.1.100,550, MCP9_![plugin#mcpgpio#pinstate#9]
endon
I think this will also work and the rest can probably also be simplified a lot by using variables.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#29 Post by Smotek7 » 16 Jan 2022, 22:16

I was interested in defining

on SendoutEvent do // %1 = port, %2 = value
SendToUDP,192.168.1.100,550,MCP%eventvalue1%_%eventvalue2%
endon

SendoutEvent I did not find in the documentation

when I turn on monitoring
on System#Boot do
MonitorRange,MCP,1,64
MCPmodeRange,1,64,1
endon

I see in the log
12399407: EVENT: MCP#9=0
12399608: EVENT: MCP#9=1

that is, it should work ?
on SendoutEvent do
SendToUDP,192.168.1.100,550,MCP%eventvalue1%
endon

or do I have to fill Sendoutevent?

You directed me, I'll test tomorrow.

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#30 Post by TD-er » 16 Jan 2022, 22:36

You can create any event you wish and call the events like this:

Code: Select all

asyncevent,MyEvent=1,2,3,4
This event you can process like this:

Code: Select all

on MyEvent do
  logEntry,"eventvalues: %eventvalue1% %eventvalue2% %eventvalue3% %eventvalue4%" 
endon

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#31 Post by Smotek7 » 16 Jan 2022, 22:57

I tested plugin 61
interesting function
if it were not a matrix then it is usable.
He uses PortA as out for matrix and portB as in with matrix.
I draw a check box "nomatrix" :D :D :D :D

That would be an interesting improvement,
For each mcp23017, one device would be defined and a scan code would be sent.

Thank you for the information
I'll try it through that asyncevent tomorrow

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#32 Post by TD-er » 16 Jan 2022, 23:40

And you may also read on the difference between asyncevent and event.
The async event is preferred as it uses less resources, but sometimes you need to have an event be processed immediately. Then you need to call event.
But this has some drawbacks, especially when using recursion.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#33 Post by Smotek7 » 17 Jan 2022, 11:46

I tested and it works for me
on SOE do
SendToUDP,192.168.1.100,550,IN%eventvalue1%
endon

on mcp#9 do
event,SOE=9=%eventvalue1%
endon

it slowed down a bit
probably by sending it in two steps
sometimes lasts 200ms
I assume this is a tenpersecond function

I have no idea how to make simply inverse logic
the only
on mcp # 9 do
if [plugin # mcpgpio # pinstate # 9] = 1
event, SOE = 9 = 0
endif
if [plugin # mcpgpio # pinstate # 9] = 0
event, SOE = 9 = 1
endif
endon

this takes me a lot of characters in the rules

I looked inside plugin 61.
Maybe I'll study it and try to edit it.
But it will be a far future.

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#34 Post by TD-er » 17 Jan 2022, 11:55

Events need only 1x an = and values separated by a comma.

Also better not to use spaces.

So you can use something like this:

Code: Select all

  asyncevent,SOE=9,![plugin#mcpgpio#pinstate#9] 
Note the exclamation mark to invert the value.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#35 Post by Smotek7 » 17 Jan 2022, 12:40

! I already tried
does not work, return !0 !1
probably because it's a number not a bit value 0/1

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#36 Post by TD-er » 17 Jan 2022, 12:48

ok, you can try to save it to a variable first, or maybe adding an extra = may also be sufficient.

Extra = :

Code: Select all

  asyncevent,"SOE=9,=![plugin#mcpgpio#pinstate#9]"
Using variable:

Code: Select all

  let,1,![plugin#mcpgpio#pinstate#9] 
  asyncevent,"SOE=9,[int#1]"

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#37 Post by Smotek7 » 17 Jan 2022, 13:21

this doesn't work for me
asyncevent,"SOE=9,=![plugin#mcpgpio#pinstate#9]"

this works
let,1,![plugin#mcpgpio#pinstate#9]
asyncevent,"SOE=9,[int#1]"

otherwise it is interesting if I use it
[plugin # mcpgpio # pinstate # 9]
so the wrong value 0/1 never comes
if I use
% eventvalue1%
so it always comes right

This is how it works for me
on mcp#9 do
let,1,!%eventvalue1%
asyncevent,"SOE=9=,[int#1]"
endon

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#38 Post by TD-er » 17 Jan 2022, 13:25

Smotek7 wrote: 17 Jan 2022, 13:21 [...]
This is how it works for me
on mcp#9 do
let,1,!%eventvalue1%
asyncevent,"SOE=9=,[int#1]"
endon
Not sure why you would use the extra = after the 9.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#39 Post by Smotek7 » 17 Jan 2022, 13:29

may not be
but when it is there = it comes to the system
rov.JPG
rov.JPG (14.16 KiB) Viewed 16202 times

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#40 Post by Ath » 17 Jan 2022, 13:57

Look at what I wrote before, where the arguments are passed separately to the SendoutEvent eventhandler.
Ath wrote: 16 Jan 2022, 21:57

Code: Select all

on SendoutEvent do // %1 = port, %2 = value
  SendToUDP,192.168.1.100,550,MCP%eventvalue1%_%eventvalue2%
endon
If you need an = sign there, then it should best be added here, in place of the _ I wrote (and what you used before), then you can write the call to asynevent correctly, using only the comma as a separator. Somewhere in the future this will bite you if you don't fix it now (and understand why).
/Ton

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#41 Post by Smotek7 » 17 Jan 2022, 23:29

@Ath
I understand

I will try to use it in such a state and I will see what the reality will be

Thanks for help
I will definitely have more questions

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#42 Post by Smotek7 » 18 Jan 2022, 11:38

I have defined rules for 27 inputs
this is the maximum that fits into one of the rule
it all slowed down
sending takes 0.6-0.7s
it is unusable

I'm probably going to study the source code for plugins 9 and 61.
I'm not a programmer, it will be difficult, but I will try

I adhere to the proverbs
Everything is possible
it's a question of time and money :D

command e.g. is monitorrange for plugin 009 or kernel?
The idea is to make a copy of plugin 61
delete unnecessary things
and adjust the required part

The structure of the plugin is described here?
https://www.letscontrolit.com/wiki/inde ... evelopment
or some link will help me

I have an Arduino IDE installed, can I do it there too?
or should I switch to Platformio

Thank you

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#43 Post by Ath » 18 Jan 2022, 11:49

Can you show your rules here?, and please wrap them in a "code" block (use the </> button in the toolbar of the forum editor, then it will look like we have shown our code samples)

Edit: There is no need to change plugin 61, you can just wire your buttons in the required matrix, and use that plugin, so you can have 16 buttons per task,so for 100 buttons that's about 7 tasks, requiring only 1 rule (eventhandler) per task, and the SendOutEvent rule you used before.
/Ton

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#44 Post by Smotek7 » 18 Jan 2022, 12:20

This is my rule

Code: Select all

on System#Boot do
 MonitorRange,MCP,1,64
 MCPmodeRange,1,64,1
endon

on SOE do 
  SendToUDP,192.168.1.100,550,IN%eventvalue1%=%eventvalue2%
endon


on mcp#1 do
let,1,!%eventvalue1% 
asyncevent,"SOE=1,[int#1]"
endon 
on mcp#2 do
let,1,!%eventvalue1% 
asyncevent,"SOE=2,[int#1]"
endon
on mcp#3 do
let,1,!%eventvalue1%
asyncevent,"SOE=3,[int#1]"
endon
on mcp#4 do
let,1,!%eventvalue1%
asyncevent,"SOE=4,[int#1]"
endon
on mcp#5 do
let,1,!%eventvalue1%
asyncevent,"SOE=5,[int#1]"
endon
on mcp#6 do
let,1,!%eventvalue1%
asyncevent,"SOE=6,[int#1]"
endon
on mcp#7 do
let,1,!%eventvalue1%
asyncevent,"SOE=7,[int#1]"
endon
on mcp#8 do
let,1,!%eventvalue1%
asyncevent,"SOE=8,[int#1]"
endon
on mcp#9 do
let,1,!%eventvalue1%
asyncevent,"SOE=9,[int#1]"
endon
on mcp#10 do
let,1,!%eventvalue1%
asyncevent,"SOE=10,[int#1]"
endon
on mcp#11 do
let,1,!%eventvalue1%
asyncevent,"SOE=11,[int#1]"
endon
on mcp#12 do
let,1,!%eventvalue1%
asyncevent,"SOE=12,[int#1]"
endon
on mcp#13 do
let,1,!%eventvalue1%
asyncevent,"SOE=13,[int#1]"
endon
on mcp#14 do
let,1,!%eventvalue1%
asyncevent,"SOE=14,[int#1]"
endon
on mcp#15 do
let,1,!%eventvalue1%
asyncevent,"SOE=15,[int#1]"
endon
on mcp#16 do
let,1,!%eventvalue1%
asyncevent,"SOE=16,[int#1]"
endon
on mcp#17 do
let,1,!%eventvalue1%
asyncevent,"SOE=17,[int#1]"
endon
on mcp#18 do
let,1,!%eventvalue1%
asyncevent,"SOE=18,[int#1]"
endon
on mcp#19 do
let,1,!%eventvalue1%
asyncevent,"SOE=19,[int#1]"
endon
on mcp#20 do
let,1,!%eventvalue1%
asyncevent,"SOE=20,[int#1]"
endon
on mcp#21 do
let,1,!%eventvalue1%
asyncevent,"SOE=21,[int#1]"
endon
on mcp#22 do
let,1,!%eventvalue1%
asyncevent,"SOE=22,[int#1]"
endon
on mcp#23 do
let,1,!%eventvalue1%
asyncevent,"SOE=23,[int#1]"
endon
on mcp#24 do
let,1,!%eventvalue1%
asyncevent,"SOE=24,[int#1]"
endon
on mcp#25 do
let,1,!%eventvalue1%
asyncevent,"SOE=25,[int#1]"
endon
on mcp#26 do
let,1,!%eventvalue1%
asyncevent,"SOE=26,[int#1]"
endon
on mcp#27 do
let,1,!%eventvalue1%
asyncevent,"SOE=27,[int#1]"
endon

if i understood plugin 61
has Port A as output and Port B as input
foreigner tests the matrix 50 times per second.
I didn't see there that I could use Port A as input and also Port B as input
foreign 16 inputs
I'm wrong?

This is what I would try to modify, 2x input port.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#45 Post by Smotek7 » 18 Jan 2022, 12:29

I see that there is also a direct mod for PCF8574
Foreign I need mcp23017 direct mod.
But it also doesn't exist.

User avatar
Ath
Normal user
Posts: 1807
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 16/12 tasks ?

#46 Post by Ath » 18 Jan 2022, 13:17

Smotek7 wrote: 18 Jan 2022, 12:20 if i understood plugin 61
has Port A as output and Port B as input
foreigner tests the matrix 50 times per second.
I didn't see there that I could use Port A as input and also Port B as input
foreign 16 inputs
I'm wrong?

This is what I would try to modify, 2x input port.
I think you misunderstand how P61 works.
The plugin supports a set of 16 keys, connected in a 4x4 matrix (like this or this or this), and connected using 8 ports of the mcp. Each button generates a unique ScanCode value that is passed on to an event. But as these 16 buttons can all be handled by 1 task & 1 rule, instead of 16 separate rules for responding to monitor events, rules-performance is not an issue.

Not sure how much work it would be to adapt the plugin to support 2 keypads (matrices), using all 16 ports, and thus 32 buttons, in 1 task, haven't looked that close at the source code yet.
/Ton

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#47 Post by TD-er » 18 Jan 2022, 14:57

The posted rules can be made quite a bit smaller, by performing the invert in the block where you handle the SOE event.

Code: Select all

on SOE do 
  let,2,!%eventvalue2% 
  SendToUDP,192.168.1.100,550,IN%eventvalue1%=[int#2]
endon

on mcp#1 do
  event,"SOE=1,%eventvalue1%"
endon 
[...] (etc)
Just used the var#2 here, as it is the 2nd eventvalue, but that doesn't really matter.
Also changed asyncevent into event here as in this case it will improve execution speed.

N.B. Moving the boot event to the end of the file may also improve speed slightly.

But I think we should add an %eventvalue0% in ESPEasy to make rules like these a lot simpler.
My idea is to let %eventvalue0% be the string part between # and =

An example of how this (not yet implemented) eventvalue0 should be used:

Code: Select all

on mcp do
  let,1,!%eventvalue1% 
  SendToUDP,192.168.1.100,550,IN%eventvalue0%=[int#1]
endon 
This would then be enough to handle all mcp events.
Maybe you need to add some check on the range of %eventvalue0% so it would only act on those pins that really matter.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#48 Post by Smotek7 » 18 Jan 2022, 15:50

So I understood correctly how plugin 061 works.
for MCP23017 it is a 9x8 foreign 72 input matrix
The problem is that I already have the PCB designed and also assembled
One input per board is one input MCP23017

The foreign matrix doesn't solve my problem.

I thought I just needed a short click on the switches.
But there are a few window contacts that are closed when idle.
As if the button was pressed. What is another matrix problem.

The output must be Scancode and pin status.

I looked in plugin 61, I'll try to make an adjustment.
Maybe it'll be ugly hardcode.

Smotek7
Normal user
Posts: 89
Joined: 01 Aug 2020, 16:18
Location: SK

Re: 16/12 tasks ?

#49 Post by Smotek7 » 18 Jan 2022, 15:55

@TD-er
I will also test this possibility
I tried to do something at the beginning but it didn't work for me.
I'm not currently at HW, I'll test tonight.

TD-er
Core team member
Posts: 6349
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: 16/12 tasks ?

#50 Post by TD-er » 18 Jan 2022, 16:19

How is the PCB with buttons now designed?
1 common rail and N wires, one for each button?

Maybe also show some picture, or small diagram?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests