matth-x / MicroOcpp

OCPP 1.6 / 2.0.1 client for microcontrollers
MIT License
345 stars 149 forks source link

Port - NXP iMX RT1064 - CUSTOM_TIMER #254

Open GanesanGuru opened 9 months ago

GanesanGuru commented 9 months ago

Hi @matth-x , I've follow the steps and when I tried to connect the MO_CUSTOM_TIMER to iMX RT1064 EVK, the mongoose connection/MO_CUSTOM_WS is being resetting continuously.

LWIP Network stack that is running in iMX RT1064. Hence, I've passed the sys_now to mocpp_set_timer - callback function as mocpp_set_timer(sys_now);

If I'm not passing that parameter, the code executes - but for later stages of developemnt - as timer configuration is mandatory, aid me to fix this

matth-x commented 9 months ago

Hi @GanesanGuru,

The timer should return the milliseconds. Sometimes the host system timers have a different resolution, for example 10ms, or even 1µs. A conversion to milliseconds is necessary then.

Here's an example for the ESP-IDF which configures the default tick rate of FreeRTOS to be 100 ticks per second:

https://github.com/matth-x/MicroOcpp/blob/12d4868200d9675d98ff81b9c226e5deace64c12/src/MicroOcpp/Platform.cpp#L45-L60

To make something similar, pass your own mocpp_tick_ms_espidf conversion function to mocpp_set_timer.

Note that MO expects that the timer uses the full 2^32 bit value range of unsigned long. It should take the timer ~49.7 days to reach the maximum value and afterwards it should roll over to 0. The ESP-IDF platform integration achieves that by using a separate counter for example.