The user should be given an ability to access all his devices on one page(Smart Speaker, IOS Device, WebClient and the Android Device). The user was previously allowed to access his/her web app account, the IOS app, Android App. But not the Smart Speaker. Now, this feature will allow the user to easily manage the Smart Speaker devices without many hassles.
In this post, we will be talking about the API’s that we have used to send the details of the Smart-Speaker to the server.
About the API’s
- Below is the API endpoint which will return the list of all devices present under the user’s account
We use the following endpoint
/aaa/ListUserSettings.json?/access_token=access_token |
Below is sample response :
“devices”: { “8C-39-45-cc-eb-95”: { “name”: “Device 1”, “room”: “Room 1”, “geolocation”: { “latitude”: “52.34567”, “longitude”: “62.34567” } } } |
- The second endpoint that we will be using is to add a new Device under the devices section
API Endpoint
/aaa/addNewDevice.json? |
This endpoint has the following parameters
- macid (Mac address of the device)
- name (Name of the device)
- room (Room info of the device)
- latitude (Latitude info of the device)
- longitude (Longitude info of the device)
After successfully hitting the endpoint , you’ll get the following response
{ “accepted”: true, “message”: “You have successfully added the device!”, “session”: {“identity”: { “type”: “email”, “name”: “sansyrox@gmail.com”, “anonymous”: false }} } |
Implementing the API’s
- First, we check the server for existing devices. This step is implemented primarily to check weather our current Smart Speaker is already configured or not.
get_device_info = api_endpoint + ‘/aaa/listUserSettings.json?’ param1 = { ‘access_token’:access_token } # print(access_token) if access_token is not None: device_info_response = requests.get(get_device_info,param1) device_info = device_info_response.json() # print(device_info) |
If the current device is not already configured on Server, we proceed to next step.
- Now we will configure the device with the server and then post the device settings there.
We will implement the API in the following way:
if device_info is not None: device = device_info[‘devices’] # list of existing mac ids print(device) session = device_info[‘session’] # session info identity = session[‘identity’] name = identity[‘name’] params2 = { ‘macid’: macid, ‘name’: name, ‘device’: ‘Smart Speaker’, ‘access_token’: access_token } for dev in device: if dev == macid: print(‘Device already configured’) return else : adding_device = requests.post(add_device_url, params2) print(adding_device.url) |
To extract the mac address from the speaker and pass it as the params , we use a python library called UUID and this is how SUSI Smart Speaker is displayed on the web client(chat.susi.ai).
Resources
- https://github.com/fossasia/susi_api_wrapper
- https://github.com/fossasia/susi_server
- https://docs.python.org/2/library/uuid.html
- https://chat.susi.ai/
Tags