import conf, json ,time from boltiot import Sms, Bolt minimum_limit = 290 maximum_limit = 330 mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID) sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER) while True: print ("Reading sensor value") response = mybolt.analogRead('A0') data = json.loads(response) print("Sensor value is: " + str(data['value'])) try: sensor_value = int(data['value']) if sensor_value > maximum_limit or sensor_value < minimum_limit: print("Making request to Twilio to send a SMS") response = sms.send_sms("The Current temperature sensor value is " +$ print("Response received from Twilio is: " + str(response)) print("Status of SMS at Twilio is :" + str(response.status)) except Exception as e: print ("Error occured: Below are the details") print (e) time.sleep(10)
Tabs and spaces are shown as whitespace on your screen.This is because there is no rule on how wide a tab character should be. Python expects the rest of the lines to have same indentation as the first line.
Go to the settings of your text editor. Click on enable the " convert tabs to spaces". This method replaces tab character with n space characters or press Ctrl and T. Once the the property panel opens tick the Tabs as spaces.
In your python editor use Edit> Untabify region. This converts tab to spaces.
We must indentation (spaces before statements after lops,if-else,function initialisation etc,.)whlle using loops,if-else statements,functions etc.,. in python in python language. You have to give some spaces infront of statements inside the loop we use,inside any function we use, and to all statements for which if-else ,try -execpt conditions applied by us.
NOTE: we must use spaces all over the code or tab spaces all over the code ,any one only. It is not right of using sometimes spaces and sometimes tabs in the same code.
That’s why ,you are getting that type of error as "inconsistent use of tabs and spaces"
So , correct them for proper execution of the code.
THE CODE WILL BE LIKE THIS :
These spaces are must and should in python language. Without them we can’t our programs. These are because to seperate the statements of loops,functions from other statements we use in remaining program. So that compiler can know which statements are main and which are of loops and conditions.
I hope it will be helpful to you.
Here in the while loop, in the try code block the if condition should have the indentation same as that in the previous line then only the next lines to the if condition till the except will be inside the if condition as a result there will be no indentation error because python uses indentation to indicate a block of code.
The if statement has the wrong indentation. Since it a part of ‘try’ block the if statement should have same indentation as line 13(which also is part of same block).The indentations of code in a block must all be the same. Similarly lines 15 to 18 are part of ‘if’ block so it must be indented accordingly. The concept of code blocks can be referred to further the understanding and use of indentation
In this the main error is the indentation of try and if satetment is wrong.
The if statement after the try: statement has to be inclined with the sensor_value statement as they are within the indent of the try: statement —> See Below the picture it is correctly done there and avoid using multiple Indentation Spaces(_ _) in one word variable as it may Misinterpret the interpreter and
make the dollar sign($) in the line
[ response = sms.send_sms("The Current temperature sensor value is " +$) ] to
[ response = sms.send_sms("The Current temperature sensor value is " +sensor_value) ]
← See below the picture →
I am using python Ver - (3.10.8) if any further problem arises update the version of python to (3.10.8) and this will
solve your problem.