In my case, two WiFi LoRa 32 (V2) modules work. One measures the milling spindle speed (tachometer). The second one, based on this data (sent via LoRa) controls the milling machine remotely.
However, once in a while (every several dozen minutes) communication between modules must occur in the opposite direction. The speed measuring module must receive a packet with the parameters needed to calculate the speed.
I want the information about the current speed of the spindle to reach the milling module as often as possible.
Pulses (tics) from the HALL sensor are counted through interrupts. Sending the package takes about 0.5 seconds. I set the program so that once every 0.6 seconds the speed is sent.
As a result, the time during which the module listens for transmission to it is very short compared to the time when the packet was sent and the transmission to the spindle speed measuring module must be repeated many times to be received.
How should the best send and receive LoR packets be connected correctly?
This is the maximally simplified version of loop () (Arduino IDE):
void loop () {
int packetSize = LoRa.parsePacket ();
if (packetSize) {
detachInterrupt (digitalPinToInterrupt (HALL_sensor_Pin));
cbk (packetSize);
attachInterrupt (digitalPinToInterrupt (HALL_sensor_Pin), pickrpm, FALLING);
};
if (Sending_Timer.onRestart ()) {
detachInterrupt (digitalPinToInterrupt (HALL_sensor_Pin));
Actual_Speed = ticks * Speed_multiplier;
LoRa.beginPacket ();
LoRa.print (Actual_Speed);
LoRa.endPacket ();
Sending_Timer.restart ();
ticks = 0;
attachInterrupt (digitalPinToInterrupt (HALL_sensor_Pin), pickrpm, FALLING);
}
}
Tomasz