@Amrita_dey there seems to be an error in configuration file. You must have both used the variable bolt_api_key in the configuration file. In the main script you have used bolt_api_key variable which isn’t present in the configuration file. Correct that and it will be good to go
Remove the ‘’’‘configurations … ‘’’’ line on first line. That is not a python language statement of any kind.
For all the declared variables, make sure to close the inverted commas, so that it is properly declared as a string. Example -
API = "this is my API key"
Your telegram bot ID is also incorrect. Go through the module where you created the bot from BotFather. The Token number is your bot_id.
Yes I was talking about this page. Strings in Python are enclosed in " “”. You haven’t closed any string. Also do correct the bot ID.
Go through the training content once again so those mistakes can be rectified
Yes, that is the token. You can delete the this post with image as it contains your telegram API credentials.
@Amrita_dey you haven’t specified which pin you are using to get the data. It must and should be A0 pin in case of Bolt module.
So, write get_sensor_value_from_pin(“A0”)
Indentation is also wring in above case. The of block statements are not properly indented.
Moreover, this code is of no significance because you must be going through the Telegram section of the training. So go through that once and then all of your doubts will be cleared.
There are a lot of changes in the code.
except block are supposed to be on the same indent.
if block, sensor_value and
return are supposed to be on the same indent.
Other than that, add ‘bot’ in front of the bot_id.
You can refer to the training as well as below code for the reference.
def get_levelsensor_value_from_pin(pin): try: mybolt.serialWrite("Level") response = mybolt.serialRead('10') print(response) data = json.loads(response) if data["success"] != 1: print("Request not successfull") print("This is the response->", data["value"]) return -999 levelsensor_value = int(data["value"]) return levelsensor_value except Exception as e: print("Something went wrong when returning the sensor value") print(e) return -999
The error statement in the output has it mentioned where the error is. Please try to locate the error and match with the one provided in the training. If you are still not able to resolve it, let us know if the forum.
do i need to change the value,level?
i just changed the pin to A0…
and just pasted the same as shown in above…
Yes, also the return statement along with it. I have shared a sample code for the reference. You have not made any changes from the last time you shared the image.
Also, you need to execute the function you have created.
def functionname() only CREATES the function. But to run it, you have to execute it as well. Please go through the modules thoroughly to have a brief understanding of the functions, indentation etc.
Hey, there’s no need to change pin to A0. Its a parameter inside the parentheses in the function definition through which an argument is sent to the function when it is called, in this code pin number will be argument to be passed while calling the function. Also, your code have indentation error at sensor_value and return sensor_value. Just paste above mentioned code. Also, you are executing only code 1 from module which is just defining a function to get sensor value from pin. It won’t return anything as it isn’t calling any function. In this module, complete code is divided into 3 parts, first code is defining function to get sensor value which you are trying you execute, code 2 is defining function to send message to telegram channel via bot and code 3 is used to call these functions by passing required arguments like pin number and telegram message. Try to run complete code which is specified in module without any indentation error.
then i will keep it as pin…
and what will i change in sensor_value and return_value
i m not able to solve the error i m doing…please help me if u can elaborate what is needed to be written in place of it
This is the complete code in training module. you need to reduce the indentation of sensor_value and return statement lines, so that they come exactly below if statement. Try to go through module code, you will get the error.
actually i m confused about what to put in “pin”,“value”,message"…so shall i keep those place as it is or i have to put some values
Your query is unclear. In pin and Value you have to put the ‘value’ (eg. 0 or 1 for digital and 0-255 for analogwrite) in correspondent to the pin (GPIO - 0,1,2,3,4). With A0 pin you can read values ranging from 0-1023.
But, since everything is already pre-written for you in the code section of the module, I am not able to understand your query.
Please elaborate on the issue, and let me know if we need to connect on a zoom meet regarding this query.
You have to power the Bolt module and wait to make sure the Green LED is stable. Only then the Bolt module be connected to Cloud, it will return with the desired outputs.
When the Bolt module is Offline, it’ll return with the statement you saw there. You can test your module from the API section in the Bolt Cloud as well.
Let me know if you have any other queries.
What is the threshold value you put?