Setup google chatbot with rasberi pi38/31/2023 ![]() ![]() With the Raspberry Pi now updated let’s install the tools we will need to set up our Raspberry Pi Twitter Bot. The first thing we should do is make sure our Raspberry Pi is up to date by running the following commands on it. ![]() ![]() Import requests from th import HTTPBasicAuth import time TOKEN = "A1E-MeQ9eYmq8Rj1sID5c1LAR6Pj7bD9ws" # Assign your Ubidots TOKEN DEVICE_LABEL = "advantech-wise" # Ubidots Device Label WISE_IP = "192.168.1.24" # Assign the WISE IP WISE_ACCOUNT = 'user' # WISE account access WISE_PASS = '00000000' # WISE account password # GET Request to the WISE REST def get_wise_data(account, password): # Retrieve information about the analog input values r_analog = requests.get(' + WISE_IP + '/ai_value/slot_0/', auth=HTTPBasicAuth(account, password)) response_analog = r_analog.json() # Assign the value of the channel 0 to a new variable ai_0 = response_analog # Assign the value of the channel 1 to a new variable ai_1 = response_analog # Retrieve information about the analog input values r_digital = requests.get(' + WISE_IP + '/di_value/slot_0/', auth=HTTPBasicAuth(account, password)) response_digital = r_digital.json() # Assign the value of the channel 0 to a new variable di_0 = response_digital # Assign the value of the channel 1 to a new variable di_1 = response_digital return ai_0, ai_1, di_0, di_1 # Build the payload to be sent def build_json(variable_1, value_1, variable_2, value_2, variable_3, value_3, variable_4, value_4): try: data = data = build_json("analog_input_0", value_1, "analog_input_1", value_2, "digital_input_0", value_3, "digital_input_1", value_4) print data r = requests.post(url=url, headers=headers, json=data) print r.json() #return r.json() except: pass if _name_ = "_main_": while True: # Assign the sensors readings ai_0, ai_1, di_0, di_1 = get_wise_data(WISE_ACCOUNT, WISE_PASS) # POST the sensor readings to Ubidots post_ubidots(DEVICE_LABEL, ai_0, ai_1, di_0, di_1) time. With our API tokens handy we can now start setting up and writing our Raspberry Pi Twitter bot. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |