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}

Now I’ve tried to send messages to Telegram using the WiFi connection onboard the Pico LTE and I could send different text messages to Telegram flawlessly. But it’s not working when I use the LTE modem in the board, It always send the same text message. Could someone try If it is me or is the code in the SDK provided that has a bug.

Hi,

Could you enable the debugging logs and share them? Please refer to this document for instructions.

Hi, thanks for your directions. Here you have the code and debug info with the debug level set to zero. Note that today, at first, the modem was registered to the network but couldn’t send messages. So, I used the Python script to send AT commands to send the reset command «AT&F», and after that, the modem worked again flawlessly. I’m sending it to a group chat, but it’s the same problem with a private chat with the Telegram bot. With a WiFi connection, it works perfectly.

###############################################

Two different messages to Telegram for testing purposes

###############################################

from pico_lte.core import PicoLTE
from pico_lte.common import debug

debug.set_level(0)

picoLTE = PicoLTE()

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

##########################
#Debug info from the Test scrip:
##########################

MPY: soft reboot
DEBUG: Power status: 0
DEBUG: Power status: 0
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: COM: {‘response’: [‘OK’], ‘status’: 0}
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
INFO: Sending message to Telegram channel…
DEBUG: Response: [‘\r\n+CREG: 0,5\r\n\r\nOK\r\n’]
DEBUG: Processed: [‘+CREG: 0,5’, ‘OK’]
DEBUG: Desired: +CREG: 0,5
DEBUG: check_network_registration : {‘response’: [‘+CREG: 0,5’, ‘OK’], ‘status’: 0}
DEBUG: success : {‘response’: [‘+CREG: 0,5’, ‘OK’], ‘status’: 0}
DEBUG: register_network : {‘status’: 0, ‘response’: [‘+CREG: 0,5’, ‘OK’], ‘interval’: 0}
DEBUG: Response: [‘\r\n+CGACT: 1,1\r\n+CGACT: 2,0\r\n\r\nOK\r\n’]
DEBUG: Processed: [‘+CGACT: 1,1’, ‘+CGACT: 2,0’, ‘OK’]
DEBUG: Desired: +CGACT: 1,1
DEBUG: check_pdp_context_status : {‘response’: [‘+CGACT: 1,1’, ‘+CGACT: 2,0’, ‘OK’], ‘status’: 0}
DEBUG: success : {‘response’: [‘+CGACT: 1,1’, ‘+CGACT: 2,0’, ‘OK’], ‘status’: 0}
DEBUG: get_pdp_ready : {‘status’: 0, ‘response’: [‘+CGACT: 1,1’, ‘+CGACT: 2,0’, ‘OK’], ‘interval’: 0}
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: set_ssl_context_id : {‘response’: [‘OK’], ‘status’: 0}
DEBUG: Processed: [‘CONNECT’]
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: set_server_url : {‘response’: [‘OK’], ‘status’: 0}
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: get : {‘response’: [‘OK’], ‘status’: 0}
DEBUG: Processed: [‘+QHTTPGET: 0,200,252’, ‘CONNECT’, ‘{“ok”:true,“result”:{“message_id”:57,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871974,“text”:“Message_1”}}\r’]
DEBUG: read_response : {‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:57,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871974,“text”:“Message_1”}}\r’], ‘status’: 0}
DEBUG: success : {‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:57,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871974,“text”:“Message_1”}}\r’], ‘status’: 0}
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:57,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871974,“text”:“Message_1”}}\r’], ‘interval’: 0}
INFO: Sending message to Telegram channel…
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: Response: [‘\r\nOK\r\n’]
DEBUG: Processed: [‘OK’]
DEBUG: get : {‘response’: [‘OK’], ‘status’: 0}
DEBUG: Processed: [‘+QHTTPGET: 0,200,252’, ‘CONNECT’, ‘{“ok”:true,“result”:{“message_id”:58,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871982,“text”:“Message_1”}}\r’]
DEBUG: read_response : {‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:58,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871982,“text”:“Message_1”}}\r’], ‘status’: 0}
DEBUG: success : {‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:58,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871982,“text”:“Message_1”}}\r’], ‘status’: 0}
INFO: Result: {‘status’: 0, ‘response’: [‘+QHTTPGET: 0,200,252’, ‘{“ok”:true,“result”:{“message_id”:58,“from”:{“id”:7110858784,“is_bot”:true,“first_name”:“Test Pico LTE”,“username”:“Test_BOT”},“chat”:{“id”:-1234567890123,“title”:“Telegram Group”,“type”:“supergroup”},“date”:1718871982,“text”:“Message_1”}}\r’], ‘interval’: 0}

When you use the SDK in the dev branch, this issue should be resolved. Please try it and let me know.

Thanks, It solved the problem of wrong cache. Now the code works as expected.

1 Like