You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had two bots connected to hub 2, and was using python to create a program to get temperature and humidity data from hub 2 and a program to run the bots. the API version is v1.0.
It was after updating the firmware that the error started to appear.
Expected Behavior
Hub 2 was writing temperature and humidity data to a text file every second and displaying it in a bat file. In the bot, a python file was started when the condition was reached, and it behaved like a switch being pressed with it.
Steps To Reproduce
The only thing that has changed from before is the firmware update.
Logs
-----------Bot---------------
import requests
import json
import tkinter.messagebox as messagebox
auth_key = 'Token'
device_id = 'deviceid'
url = f"https://api.switch-bot.com/v1.1/devices/{device_id}/commands"
headers = {
"Authorization": f"Bearer {auth_key}", # Bearer
"Content-Type": "application/json; charset=utf8"
}
params = {
"command": "turnOff",
"parameter": "default",
"commandType": "command"
}
response = requests.post(url, headers=headers, data=json.dumps(params))
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code == 200:
messagebox.showinfo('shutter', 'shuttered')
else:
messagebox.showerror('Error', f"miss: {response.text}")
~~~~result~~~~Status Code: 401Response: {"message":"Unauthorized"}-----------Hub2-----------------import requestsimport timefrom datetime import datetime# APIAPI_TOKEN = 'Token' # deviceIDDEVICE_ID = 'deviceid' # headersheaders = { 'Authorization': API_TOKEN, 'Content-Type': 'application/json; charset=utf8'}# endpointURLurl = f'https://api.switch-bot.com/v1.0/devices/{DEVICE_ID}/status'file_path = 'humidity.txt'# datagettry: while True: try: # send request response = requests.get(url, headers=headers) response.raise_for_status # get responce for json data = response.json() # datetime now current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # hub2 data if 'body' in data and 'humidity' in data['body']: humidity = data['body']['humidity'] data_str = f'{humidity}\n' # write file with open(file_path, 'w', encoding='utf-8') as f: f.write(data_str) # print print(f'{humidity} %') else: print('Humidity data could not be obtained.') except requests.exceptions.RequestException as e: print(f'A request error has occurred.: {e}') # wait time.sleep(1)except KeyboardInterrupt: print("Terminate data acquisition.")~~~~result~~~~500 Server Error: Internal Server Error for url: https://api.switch-bot.com/v1.0/devices/{deviceID}/status↑url destination output{"message":"Unauthorized"}
Configuration
#
Environment
OS:Windows 11
Software:Python 3.7 and Python 3.12
Additional Context
No response
The text was updated successfully, but these errors were encountered:
Analysis
I had two bots connected to hub 2, and was using python to create a program to get temperature and humidity data from hub 2 and a program to run the bots. the API version is v1.0.
It was after updating the firmware that the error started to appear.
Expected Behavior
Hub 2 was writing temperature and humidity data to a text file every second and displaying it in a bat file. In the bot, a python file was started when the condition was reached, and it behaved like a switch being pressed with it.
Steps To Reproduce
The only thing that has changed from before is the firmware update.
Logs
Configuration
#
Environment
Additional Context
No response
The text was updated successfully, but these errors were encountered: