Sedmund 03/13/2024 09:44 AMHello!
Me and my friend are working on a project where we measure distance using an ultrasonic sensor and send this data to The Things Network. We send the data using a M5LoRaWAN868 external Lora module and we want to implement a way to establish communication between the LoRa module container and the sensor container. For example, at this moment we have a main file that imports both the LoRa module class and the sensor class and then runs them in tasks. We can then retrieve the sensor values and send them by using the main file as a mediator between them. The main file also contains a deep sleep call, which auto runs the installed containers again when it wakes up.
This method we have used above (simply running the different classes in tasks) works but they are not running simultaneously.
We assume it would be almost the same when working with services, however with the communication working between the installed containers. We've been reading the services documentation but is there any examples that shows the containers running for example while true loops?
For example in the code below, which we use to test the ultrasonic sensor:
import dyp_a01 show DYP_A01
import gpio
class sensorModule:
sensorValue := 0
sensor := null
constructor tx_/int rx_/int:
sensor = DYP_A01
// --tx_pin=tx not used
--rx_pin=rx_
start:
task::sensor_read
sensor_read:
print "Sensor reading started."
while true:
sensorValue = sensor.range
sensor.off
get_sensorValue -> int:
return sensorValue
and then we start the reading in the main file:
sensorModule := sensorModule sensor_tx sensor_rx
loraModule.start
sensorModule.start
We would want to have these running independently without blocking one another as they could do with tasks, if the Port.read waits for data. How would we go about implementing services to these classes? For example the one above.