I always send the same message to Telegram

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

This week I tryed the code with ThinkSpeak without problems. The data that arrives to ThinkSpeak changes as the distance with the ultrasond sensor change.

Now, I tried a simple code to send two difent messages to Telegram and It doesn’t work as espected. Always arrive the same message to Telegram. I post the results here for help. If I stop the program and then write a new text to send a diferent message it works.

#Code start here

from pico_lte.core import PicoLTE
from pico_lte.common import debug
import utime as time

picoLTE = PicoLTE()

debug.info(“Sending message to Telegram channel…”)
result = picoLTE.telegram.send_message(“PicoLTE Telegram Example”)
debug.info(“Result:”, result)

time.sleep(10)

debug.info(“Sending second message to Telegram channel…”)
result2 = picoLTE.telegram.send_message(“PicoLTE Telegram Example - Second Message”)
debug.info(“Second message result:”, result2)

#Console output here
INFO: Sending message to Telegram channel…

INFO: Result: {‘status’: 0, ‘response’: [‘{“ok”:true,“result”:{“message_id”:22,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“dcerver_bot”},“chat”:{“id”:xxxxxxxxxxxxxx,“title”:“TEST GROUP”,“type”:“supergroup”},“date”:1718531610,“text”:“PicoLTE Telegram Example”}}’], ‘interval’: 0}

INFO: Sending second message to Telegram channel…

INFO: Second message result: {‘status’: 0, ‘response’: [‘{“ok”:true,“result”:{“message_id”:23,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“dcerver_bot”},“chat”:{“id”:xxxxxxxxxxxxxx,“title”:“TEST GROUP”,“type”:“supergroup”},“date”:1718531657,“text”:“PicoLTE Telegram Example”}}’], ‘interval’: 0}