lnbits/bitcoinswitch

Bug: Multiple switch pins cannot be switched on at the same time.

Opened this issue · 1 comments

Initial situation: Multiple switch pins are configured.

As soon as a switch pin, e.g. (pin 12) is switched for 15 min, payments for other switch pins, e.g. pin 17, are accepted but not switched.

It would be desirable if during the switch-on time of a pin, further pins were also switched as expected after payment.

Thank you very much.

Ideally this would be implemented by two "threads" aka Tasks:

  • the first task (let's call it the COMM task) is fetching data from the websocket, parsing it and putting commands into the queue shared with the second task
  • the second task (let's call it the GPIO task) has an internal state which is a dictionary STATE[pin] = duration_left) and has read-only access to the queue

the GPIO task has a resolution of let's say 1ms:

  • every cycle it looks into the queue, if there is a command there, it removes it from the queue and performs STATE[pin] += duration
  • every cycle it turns off all GPIO pins where STATE[pin] == 0 and turns on all pins where STATE[pin] > 0
  • every cycle it does if STATE[pin] > 0: STATE[pin] -= 1

PS: Tasks tutorial is here: https://randomnerdtutorials.com/esp32-dual-core-arduino-ide/

PPS: We don't need to do the hardware tasks that can only be run on ESP32-S series (which are dual core), but no on ESP32-C series (which are single core). We can emulate the tasks with a single thread, which is non-blocking.