Skip to content

abe-winter/python-example-module

Repository files navigation

python example module modular resource

This module implements the Viam Sensor API in a wifi_sensor:linux model. With this model, you can gather information about connected wireless signals on your Linux machine, including wifi network availability, signal strength, and noise.

Requirements

You must have a Linux machine to use the python example module modular resource.

Build and run

To use this module, follow these instructions to add a module from the Viam Registry and select the wifi_sensor:linux model from the python-example-module module.

Configure your wifi_sensor:linux component

Note

Before configuring your wifi_sensor:linux component, you must create a machine.

Navigate to the Config tab of your machine's page in the Viam app. Click on the Components subtab and click Create component. Select the sensor type, then select the wifi_sensor:linux model. Enter a name for your component and click Create.

Note

For more information, see Configure a Machine.

Attributes

There are no attributes available for configuration with this service.

Example configuration

{
  "components": [
    {
      "name": "my-wifi-sensor",
      "model": "viam:wifi_sensor:linux",
      "type": "sensor",
      "namespace": "rdk",
      "attributes": {},
      "depends_on": []
    }
  ],
  "modules": [
    {
      "type": "registry",
      "name": "viam_python-example-module",
      "module_id": "viam:python-example-module",
      "version": "0.0.13"
    }
  ]
}

Next steps

Once the wifi_sensor has started collecting data, you can view reported readings from the Data tab in the Viam app, under the Sensors subtab.

You can also:

Learning resources

Writing a module

This module includes basic module logic in its src/wifi_sensor.py file. Follow the instructions to create your own module to learn how to write a custom module that extends a Viam API.

Setting up a virtualenv

This module includes a setup.sh file to help configure a virtualenv for this module. Follow the instructions to prepare your Python virtual environment to learn how to set up and distribute a virtualenv configuration with your custom module.

Use CI to automatically publish on release

This module includes a .github/workflows directory, which contains workflows that you can use to automatically publish a new version of your module to the Viam registry when you create a GitHub release. For more information, see Update a module using a GitHub action.

Repository contents

  • src: Directory containing Python source code.
  • exec.sh, setup.sh: Entrypoint file and dependencies setup, and ran on your machine when running the module.
  • Makefile: Builds and bundles your module into a tarball for distribution.
  • .github/workflows: Uploads the module automatically when you create a GitHub release
  • meta.json: The Viam module configuration file.
  • requirements.txt: A file that defines your module's required dependencies. When run as a module, setup.sh installs these in the virtualenv.

Forking this repo

If you want to copy this repository and use it as a foundation for your own module, you'll need to make a few changes:

Create your own meta.json

  1. Get the Viam CLI
  2. Rename the existing meta.json to meta.json.old
  3. Use viam module create to create a copy in your own account
  4. Copy all the fields except name from meta.json.old (your choice whether to make it public or private)

Change all references to the viam namespace

You'll need to change all the namespace references in the codebase ('viam') to the namespace of your organization on Viam.

  1. You should already have done this in meta.json above
  2. In the "model" field in meta.json (on line 9 when this was written)
  3. In the ModelFamily in wifi_sensor.py, around here.

Set a secret if you want to use Github CI

Instructions for setting the secret are here.

Troubleshooting

  • If you are not seeing sensor readings appear in the Logs tab on the Viam app, make sure that both the Data capture and Cloud sync features are enabled on the data management service, and that your wifi_sensor:linux component is configured to capture data.

About

Python example module with a sensor and registry integration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •