I am trying to make smart irrigation system using dht11 sensor and water level sensor with bolt iot and arduino.I am getting errors in arduino code and python code .Could anyone help me??
This is my python code .Plzz check and tell me whether it is correct or not.I have also attached screenshot of errors .
import json, requests, time
from boltiot import Bolt
import requests # for making HTTP requests
import json # library for handling JSON data
import time # module for sleep operation
from boltiot import Bolt # importing Bolt from boltiot module
“”“Configurations for home_automation.py”""
Bolt IoT Credentials
api_key = “************************” #API Key of Bolt Cloud
device_id = “BOLT******” #Device ID
Telegram Credentials
telegram_chat_id = “@smart_irrigation01”
telegram_bot_id = “bot5099747110:AAEgtaDanIrrNnVpUdZ9joI5l55JsS3FlTg”
URL = “https://api.telegram.org/” + telegram_bot_id
threshold_value = 40
mybolt = Bolt(api_key, device_id)
def get_levelsensor_value_from_pin(pin):
"""Returns the sensor value. Returns -999 if request fails"""
try:
responseA=mybolt.serialBegin(9600)
responseB=mybolt.serialWrite('getAnalogdata')
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
def send_telegram_message(message):
"""Sends message via Telegram"""
print("Sending telegram message .....")
url = URL+ "/sendMessage"
data = {
"chat_id": telegram_chat_id,
"text": message
}
try:
response = requests.request("POST",
url,
params=data)
print("This is the telegram response=>")
print(response.text)
telegram_data = json.loads(response.text)
return telegram_data["ok"]
except Exception as e:
print("An error occurred in sending message via Telegram")
print(e)
return False
while True:
# Step 1 : Check Device Status
print("Checking device Status .....")
response = check_device_status()
if response != True:
time.sleep(10)
levelsensor_value = get_levelsensor_value_from_pin('A1')
print("The level sensor value is:", levelsensor_value)
time.sleep(10)
continue
if levelsensor_value == -999:
print("Request was unsuccessfull. levelsensor Skipping.")
time.sleep(10)
continue
if levelsensor_value >= threshold_value:
message = "Water level reached its level.Turning off the Motor"
print(message)
send_telegram_message(message)
time.sleep(10)
data.append(levelsensor_value)
time.sleep(10)