This ST Schema Connector project has been designed to deploy two server instances (OAuth and Webhook Schema Connector) that will interact altogether with the device reference encoded as a JSON Web Token.
In addition, this project has been developed on top of the Python's http.server built-in module and uses the SmartThings Schema Connector Python SDK to integrate virtual devices into the SmartThings platform.
-
run.py
- Module used to call the OAuth and Webhook services. -
/lib
-
/oauth
data
user_information
- Module that in charge of user registration and creation of JSON Web Tokens. It will create a.p
file in reference of the pickle module used to save user information in binary form.
oauth_config
config
- Module that loads the environment variables from the.env
file.
public
login.html
app.py
- Module that handles Http and provides the OAuth service.
-
/webhook
data
device_information
- Module that get data from the.p
files that contains the device information.device_info.p
- File that contains device information for Discovery Responses.device_state_info.p
- File that contains device information for State Refresh Responses.device_info_ref.txt
- Readable reference of the content at thedevice_info.p
file.device_state_info_ref.txt
- Readable reference of the content at thedevice_state_info.p
file.
webhook_config
- Module that loads the environment variables from the.env
file.my_connector
- Module that handles Interaction types with the help of the SmartThings Schema Connector Python SDK.app.py
- Module that handles Http and provides the Webhook service.
-
- Python 3.6 or greater.
- SmartThings Developer Account.
- SmartThings App (developer mode active).
-
Clone this project and install its dependencies:
git clone git@github.com:erickvneri/simple-python-schema-connector.git python3 -m pip install -r requirements.txt
-
To install the SmartThings Schema Connector Python SDK follow these instructions.
-
At your working directory, create a
.env
file following theexample.env
file (you can copy-paste the content of this last one to ease the process).
To deploy both servers, you'll need two separate terminals.
-
To deploy the OAuth server, run the following command at your first terminal:
python3 run.py --service oauth
-
To deploy the Webhook Schema Connector server, run the following command at your first terminal:
python3 run.py --service webhook
To expose both apps at the World Wide Web, I recommend you to use localtunnel as it allows to deploy multiple tunneling instances with no payment needed.
As we did in the last step, you'll need two separate terminals to deploy both localtunnel instances.
-
Enable tunneling service for OAuth server at your third terminal:
lt --port 5000 --print-requests
-
Enable tunneling service for Webhook server at your fourth terminal:
lt --port 8000 --print-requests
-
Access your Developer Workspace.
-
Create your project following this sequence of steps:
- New Project -> Device Integration -> SmartThings Cloud Connector -> SmartThings Schema Connector -> Name your project.
-
Click at Register App.
-
Select Webhook Endpoint and copy-paste the localtunnel url (port 8000) and include the
/my-schema-connector
endpoint as follows:https://example-webhook-url.loca.lt/my-schema-connector
-
Click Next to register your OAuth configuration. If you're using the dummy credentials from the
example.env
file, use the following values:- Client Id: dummy-client-id
- Client Secret: dummy-client-secret
-
As OAuth endpoints, copy-paste the localtunnel url (port 5000) and include the
/authorize
and/token
endpoints as follows:- Authorization URI: https://example-oauth-url.loca.lt/authorize
- Token URI: https://example-oauth-url.loca.lt/token
-
(Optional) Fill the Scopes field and click Next.
-
Fill the App Display Name field.
-
To finalize, upload a 240x240 .png image and click Save.
- From the Dashboard, tap the "+" sign and select "Device".
- At the bottom of the "By device type" section, select "My Testing Devices".
- Track your project and select it.
- Once the Login page has been deployed, you'll be able to select a few example devices for demonstration.
- Finalize the installation and test the example devices. By default, the Webhook server has enabled the logger instance from the SmartThings Schema Connector Python SDK, therefore, you'll get full detail of the interaction types received at your terminal.
To learn more about SmartThings Schema Connector integrations, please visit our main documentation or share your questions at our Community Forums.