This project shows how to quickly integrate custom sensors into or viam managed robots.
If you need to set up a robot on viam please see the setup viam readme.
git clone https://github.com/shawnbmccarthy/viam-simple-sensor
cd viam-simple-sensor
./setup_venv.sh
This will set up our python virtual environment and install the required packages
The viam server component interface allows us to create custom components which interface
with the viam-server
using the viam SDK's. Our example makes use of the Python SDK
to create custom sensors.
- log into app.viam.com
- access the robot you configured, and go to the remotes tab
- give the remote a name, for this example lets use
simple-sensor
, next selectCreate Remote
, this will show the next page:
- in the
Heading Info
text box enterlocalhost:9090
, this is the default binding that sensor_remotes.py is configured for. Now clickSave Config
at the bottom of the page, a confirmation message will appear.
Now that we have created our remote resource, we can start our proces
# run from viam-simple-sensor
./sensor_remotes.sh -l DEBUG
This will start a remote process with DEBUG
log level. By default, only WARNING
and above are logged, you should see
the output below:
2022-12-14 01:08:42,088 INFO viam.rpc.server (server.py:81) Serving on localhost:9090
Now go back to app.viam.com and select the Control
tab of your robot and select Sensors
,
here we can select Get All Readings
to see the output
To see how the code works view: static_sensor.py and sensor_remotes.py
Below are the options that can be used
./sensor_remotes.sh -h
usage: sensor_remotes.py [-h] [--host HOST] [--port PORT] [--log {DEBUG,INFO,WARNING,ERROR,FATAL}]
options:
-h, --help show this help message and exit
--host HOST, -n HOST hostname/ip rpc server will bind to
--port PORT, -p PORT port number to store
--log {DEBUG,INFO,WARNING,ERROR,FATAL}, -l {DEBUG,INFO,WARNING,ERROR,FATAL}
log level to use
With no options the defaults are:
- host = localhost
- port = 9090
- log = WARNING
We can also configure our viam server to manage the remote process, ensuring that when viam server is running the remote server will also run.
For any questions, please email me at: shawn@viam.com