This directory contains example programs making use of u-iot. Descriptions of each, including wiring diagrams for those that need them, can be found below.
-
Install Raspbian Lite on your SD card via Imager or your favorite imaging program.
-
Mount the boot directory to your host OS:
$ sudo mount /dev/XXX1 /path/to/mnt/
- NOTE: find
XXX
using$ lsblk
. It should be something likesdb1
ormmcblk0p1
.
-
Add an empty file named
ssh
to allow remote SSH into the device:$ echo "" > /path/to/mnt/ssh
-
Add network information so the Pi can connect to wifi. Copy
wpa_supplicant.conf
into the mounted directory, replacingYOUR_SSID
andYOUR_WIFI_PASSWORD
with your network information:$ cp wpa_supplicant.conf /path/to/mnt/
- NOTE: this step is unnecessary if you are using Ethernet to connect to your Pi
-
Boot up the Pi and find its IP. This can be done in one of two ways:
- Connect it to a keyboard and monitor and type
ip addr
.- If you do it this way, I recommend skipping step 6 and proceeding locally.
- Log into your router settings and find the IP it was assigned to.
- Connect it to a keyboard and monitor and type
-
SSH into the Pi:
$ ssh pi@XXX.XXX.XXX.XXX
- NOTE: the default password will be
raspberry
. I highly recommend changing this now.
-
Install Go and get the u-iot repositories:
$ sudo apt install golang
$ go get github.com/TrevorFarrelly/u-iot
$ go get github.com/TrevorFarrelly/rpi
-
Done! Run an example program, or write your own. If you are setting up a more permanent device, I recommend adding a
systemd
entry to run it automatically on startup. Instructions on how to do so can be found here.
helloworld
contains basic demonstrations of the main features of u-iot: function definition, parameter ranges, and device detection using the eventing channel. It can be run locally as it does not need GPIO, and serves as a good test device when building a new interface program.
interface
contains a basic CLI program for interacting with other u-iot devices. It supports calling one function on one device using the CallOne
keyword, or calling a function on multiple devices using CallAll
and pattern-matching device tags. NOTE: the device list that is printed on startup does not update. If new devices join after startup, they can be called, they just won't appear in the list.
relay
contains code for controlling a relay (and, thus, any 120v AC appliance) using a Pi's GPIO. If you use this code yourself, ensure that the relay you use has a 5v control voltage and supports the AC voltage/amperage you will be driving. A wiring diagram for relays I used can be found below, but note that yours may be different.
rgb
contains code for controlling an RGB LED using software PWM on a Pi's GPIO. Note that the LED I used has a common anode (negative) and I used PWM to balance brightness, when you would normally do that with different resistor values. Nonetheless, the wiring diagram can be found below.