I cant figure out what str(data['value'])) does

print("Sensor value is: " + str(data[‘value’]))
can someone explain this line of code to me.

hi @nehal3001
the syntax you have mentioned is used to get the data value in string form which means character , this function will print the output of the sensor value in words instead of numbers or symbols.
hope this reply will help you
thank you.

Hi Nehal,

If you check the response form Bolt Cloud API, it return the data in below format: https://docs.boltiot.com/docs/write-digital-output-1

 {"success": "1", "value": "1"}

and when you do ,

data = mybolt.digitalRead('A0')

Now data is a string that store the values {“success”: “1”, “value”: “1”}, you need to convert it into json.

data  = json.loads(data)

Now you can access the value of each key using the data[“key”]

For example:

print(data["value"])
print (data["success"])

Output
1
1

hi @rahul.singh1
was my reply incorrect just wanted to know

Hi @ajeshkumar36020,

No, your reply is also correct.

1 Like

@rahul.singh1
ok thankyou sir
:slightly_smiling_face:

Thank you sir, i was confused were the keyword value came from. Thank you for clearing it out for me

Thank you for helping me