/opendatacam-nodered-influxdb

Use machine vision to collect traffic data with OpenDataCam on a Nvidia Jetson Nano, and send to InfluxDB using Node-RED

MIT LicenseMIT

Nvidia Jetson and OpenDataCam to Explore Computer Vision and IoT Analytics

Using a Nvidia Jetson Nano running OpenDataCam, it simple count people and vehicles on almost any video feed, and send the data to a InfluxDB Cloud instance using Node-RED via a cellular connection for remote deployments.

Complete details and instructions for this project can be found on the Hologram blog. This page only supplies supporting information and code.

Node-RED flow

To use nodered-flow.json, you need to install additional nodes
npm install node-red-contrib-stackhero-influxdb-v2

Cellular modem setup

The D-Link DWM-222 that I used for this project required some additional setup, and you might find this information relevant for other modems as well.

Dongles intended for Windows machines will start by showing as a mass storage device for driver download, and then change to modem mode when it detects a driver. To force this switch on Linux, we use USB_ModeSwitch. There were no configuration files for my modem, so I had to create a custom config file, using the vendor and product IDs that I was able to get by running lsusb.

Bus 001 Device 005: ID 2001:ac01 D-Link Corp.

Create the config file
sudo nano /etc/usb_modeswitch.d/2001\:ac01

Copy the following contents into the file.

# D-Link DWM-222 A2
DefaultVendor=0x2001
DefaultProduct=0xac01
TargetVendor=0x2001
TargetProduct=0x7e3d
StandardEject=1
OptionMode=0

Open the udev rules file for USB_ModeSwitch sudo nano /lib/udev/rules.d/40-usb_modeswitch.rules

Add the following entry

# D-Link DWM-222 A2
ATTR{idVendor}=="2001", ATTR{idProduct}=="ac01", RUN+="usb_modeswitch '/%k'"

Restart the Jetson, and run lsusb to check if the modeswitch worked. The result should be

Bus 001 Device 005: ID 2001:7e3d D-Link Corp.

Check if ModemManager detects the modem using mmcli -L

If not the modem was probably not assigned a serial ID. This can be confirmed by running ls /dev/ttyUSB*, which should return nothing.

Assign the dongle a ID

sudo modprobe option;sudo sh -c "echo 2001 7e3d > /sys/bus/usb-serial/drivers/option1/new_id"

Running ls /dev/ttyUSB* should now return ttUSB0 to ttyUSB4

Running mmcli -L should now show the modem

The rest of the Network Manager setup instructions are in the Hologram blog post

If your USB web cam is not detected by OpenDataCam, after updating config file sudo nano ~/opendatacam/config.json

"VIDEO_INPUT": "usbcam"
  1. Verify if you have an usbcam detected

    ls /dev/video*
    # Output should be: /dev/video0
  2. Check what resolution and framerate your webcam supports, by running v4l2-ctl --list-formats-ext. In my case it was 800x600 at 7.5 FPS (15/2 FPS).

  3. Update the opendatacam/config.json file as follows

    "VIDEO_INPUTS_PARAMS": {
      "usbcam": "v4l2src device=/dev/video0 ! video/x-raw, framerate=15/2, width=800, height=600 ! videoconvert ! appsink"
    }
  4. (Optional) If your device is on video1 or video2 instead of default video0, change VIDEO_INPUTS_PARAMS > usbcam to your video device, for example if /dev/video1

Additional Information Sources