Hi, every time I run this code, the same message always arrives on Telegram. I change the distance measured with the ultrasonic sensor, and the value of the message that arrives to the Telegram chat does not change. It sends the first value and never change until I restart the script. I provide the code and debugging information. Thank you.
CODE:
#THIS IS THE SCRIPT
import json
import time
from hcsr04 import HCSR04
from pico_lte.core import PicoLTE
from pico_lte.common import debug
#debug.set_level(0)
sensor = HCSR04(trigger_pin=18, echo_pin=19)
picoLTE = PicoLTE()
while True:
distance = str(sensor.distance_cm()) + ’ cm’
print(‘Distance:’, distance)
debug.info(“Sending message to Telegram channel…”)
result = picoLTE.telegram.send_message(distance)
debug.info(“Result:”, result)
time.sleep(15) # Wait for 15 seconds before the next measurement
DEBUG INFO:
Distance: 80.10309 cm
INFO: Sending message to Telegram channel…
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,280’, ‘{“ok”:true,“result”:{“message_id”:145,“from”:{“id”:1234567890,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“XXXXX_bot”},“chat”:{“id”:XXXXXXX,“first_name”:“XXXXX”,“last_name”:“XXXXX XXXXX”,“username”:“XXXXX”,“type”:“private”},“date”:171804’], ‘interval’: 0}
Distance: 80.49828 cm
INFO: Sending message to Telegram channel…
INFO: Result: {‘status’: 0, ‘response’: [‘{“ok”:true,“result”:{“message_id”:146,“from”:{“id”:1234567890,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“XXXXX_bot”},“chat”:{“id”:XXXXXXX,“first_name”:“XXXXX”,“last_name”:“XXXXX XXXXX”,“username”:“XXXXX”,“type”:“private”},“date”:1718041233,“text”:"80.10309 cm’], ‘interval’: 0}
Distance: 23.47079 cm
INFO: Sending message to Telegram channel…
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,280’, ‘{“ok”:true,“result”:{“message_id”:147,“from”:{“id”:1234567890,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“XXXXX_bot”},“chat”:{“id”:XXXXXXX,“first_name”:“XXXXX”,“last_name”:“XXXXX XXXXX”,“username”:“XXXXX”,“type”:“private”},“date”:171804’], ‘interval’: 0}
Distance: 23.52234 cm
INFO: Sending message to Telegram channel…
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,280’, ‘{“ok”:true,“result”:{“message_id”:148,“from”:{“id”:1234567890,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“XXXXX_bot”},“chat”:{“id”:XXXXXXX,“first_name”:“XXXXX”,“last_name”:“XXXXX XXXXX”,“username”:“XXXXX”,“type”:“private”},“date”:171804’], ‘interval’: 0}
Distance: 23.83162 cm
INFO: Sending message to Telegram channel…
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,280’, ‘{“ok”:true,“result”:{“message_id”:149,“from”:{“id”:1234567890,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“XXXXX_bot”},“chat”:{“id”:XXXXXXX,“first_name”:“XXXXX”,“last_name”:“XXXXX XXXXX”,“username”:“XXXXX”,“type”:“private”},“date”:171804’], ‘interval’: 0}
Distance: 78.45361 cm