Error in the Telegram project( to sense temperature)

I have typed the whole code of telegram project and i am facing error while i ma trying to run the code. Please help me!!


I have attached all the pics.

In your last pic uploaded you have entered a double invited coma instead of semicolon for the if statement of sensor value
i.e if sensor_value= -999 "(should be : )
if you get syntax as error always check for such small mistakes…happens many a time :slight_smile:

Still getting the same error

get rid of the slash( \ ) sign in the last pic after the line …print(“sensor value exceeded threshold”)

i.e

message = "Alert ! sensor value exceeded " + str(conf.threshold) + ".The current value is" +str(sensor_value)

like said…if it is a syntax error it will either be something missing or some extra symbols that shouldn’t be at the particular place :smile:

I had also faced this problem…The training session has a few mistakes here and there :sweat_smile:

Thanks but not resolved


Now after run this is the problem

This does not seem to be a code problem. You can wait the mentioned time, or you could start fresh with a new code with the previously mentioned corrections. :no_mouth:

edit : make a new group and bot also …just for safety

What is telegram chat id and bot id…also how to copy paste in virtualbox if you know?

this is the chat id i.e …after creating group, click the group name on the top and check the info section . the text after t.me/ is your chat id and is to be written with an @
eg if it says t.me/hello then your chat id is @hello

after creating a bot in the botfather section it provides you with an api to access the bot i.e bot id

The whole thing from the 9 digit number till the ending is your bot id

use ctrl + c to copy from your laptop and ctrl+shift+v to paste in virtual box.

Hi @kr.mayank.singh,

Here your code seems fine to me but you are rate limited because of doing too many request to Bolt Cloud.

Read the API rules here https://docs.boltiot.com/docs/api-access-rules

In while loop(3rd steps), your time.sleep() should be out of if condition. Check the code below.

while True:
    # Step 1
    sensor_value = get_sensor_value_from_pin("A0")    
    print("The current sensor value is:", sensor_value)
    
    # Step 2
    if sensor_value == -999:
        print("Request was unsuccessfull. Skipping.")
        time.sleep(10)
        continue
    
    # Step 3
    if sensor_value >= conf.threshold:
        print("Sensor value has exceeded threshold")
        message = "Alert! Sensor value has exceeded " + str(conf.threshold) + \
                  ". The current value is " + str(sensor_value)
        telegram_status = send_telegram_message(message)
        print("This is the Telegram status:", telegram_status)

    # Step 4
    time.sleep(10)

Do let me know in case you need further assistance.