"The current sensor value is -999"


#1

I am working on “Social media of Things part” I wrote the code which is given but while running the code I am getting the output as the “Request was unsuccessfull.Skipping” please look in to it and do the needful
below I have attached the code and the output which I am getting


#2

Hai@yeshwanthpatel99!
As you have mentioned ,I too got stuck in the project code. but finally, I have got a solution for this.Don’t Worry…:grinning:With this post i will add the proof and the code corrections you must do.
Before that you must check the conf.py file once as you have entered the details correctly especially the chat_id and bot_id.it must be as follows :slight_smile:


The chat_id will be your channel name followed by @symbol

Now let us move on to the further coding part …
According to my observation, the code part for checking the success condition is slightly wrong so it should be like this …


I have changed that**!=1 into =1** Because i don’t know how far that part is right and what it is going to do with it so i have changed it to make it work and i got the results…so i will post the entire code and output so that you can refer from it!

after bypassing this command, it goes directly to the send_telegram_message function after validating that obtained sensor_value is greater than the threshold limit!
it works fine 100%dude…
so here are the code and the output obtained!




24

i have pressed ctrl+c

The screenshot for the telegram channel…

So Kindly refer this and do post if still your query is not resolved…I hope you had got your solution…
now you don’t get the current value is-999…:rofl:
The problem before:

The Problem’s output i got:…
28
Thank U! Happy Coding…:sunglasses:


#3

@yeshwanthpatel99 There is an indent error in your code inside the function get_sensor_value_from_pin().

The code is supposed to look like,

def get_sensor_value_from_pin(pin):
    """Returns the sensor value. Returns -999 if request fails"""
    try:
        response = mybolt.analogRead(pin)
        data = json.loads(response)
        if data["success"] != "1":
            print("Request not successfull")
            print("This is the response->", data)
            return -999
        sensor_value = int(data["value"])
        return sensor_value
    except Exception as e:
        print("Something went wrong when returning the sensor value")
        print(e)
        return -999

The lines

        sensor_value = int(data["value"])
        return sensor_value

are at the same indent level as the if data["success"] != 1:
Please make the corrections and it will work fine.


#4

Sir mine is not working correctly with same line of codes. Its giving the error

anyone plz check the codes and tell me where i am going wrong


#5

Sir if I code following ur steps .why is this coming?
“bad request.Chat not found. Error code :400”


#6

@arnabdutta31399 You have given an incorrect chat ID. The chat ID is not the name of the channel. It is a part of the invite link.
In your case, the chat ID would be arnabdutta31399.

With regards to the issue where it says that request is not successful, you are doing a string comparison instead of a integer comparison. It should be
if data["success"] != 1:


#7

okk thnk u. i will try.