It is possible to remotely control your devices from another computer, enabling you to develop and test your application directly from your development environment.
For Arduino compatible devices communication is via USB using the excellent firmata4j and jssc libraries and the diozero-provider-firmata wrapper. Make sure you set the property
FIRMATA_PORT to the serial port (COM on Windows) to which your Arduino is connected. This can be set either via the command line (e.g.
-DFIRMATA_PORT=COM5) or as an environment variable (command line takes precedence). Example command line:
java -cp tinylog-api-2.1.2.jar:tinylog-impl-2.1.2.jar:diozero-core-0.13.jar:diozero-provider-firmata4j-0.13.jar:firmata4j-2.3.8.jar:jssc-2.8.0.jar:diozero-sampleapps-0.13.jar com.diozero.sampleapps.LEDTest -DFIRMATA_PORT=COM5 12
The Particle Photon is a tiny Wi-Fi connected microcontroller. You can upload the VoodooSpark firmware to the board to enable remote control over Wi-Fi. Make sure you set the properties
PARTICLE_TOKEN correctly (either via command line or as environment variables). Example command line:
java -cp tinylog-api-2.1.2.jar:tinylog-impl-2.1.2.jar:diozero-core-0.13.jar:diozero-provider-voodoospark-0.13.jar:diozero-sampleapps-0.13.jar -DPARTICLE_DEVICE_ID=abc -DPARTICLE_TOKEN=xyz com.diozero.sampleapps.LEDTest 12
The pigpio library also comes with the pigpiod daemon process for remote access. By default (for security reasons) this process only allows communication from the Raspberry Pi device it is running on. To enable remote access pigpiod needs to be run without the
-l option. Before doing this you must be aware of the security implications, only consider this on a local network that has no inbound connectivity from the Internet. On Raspbian Jessie and later you can enable the pigpiod daemon to run as a system service:
sudo systemctl enable pigpiod.service
This will start pigpiod every time the Pi boots. To remove the
-l option which is included by default, edit
/lib/systemd/system/pigpiod.service and change the
ExecStart property, i.e.
Make sure you set the property
PIGPIOD_HOST to the hostname of your Raspberry Pi. You can also override the default pigpiod port value (8888) via the property
PIGPIOD_PORT. Again these can be set either via command line or as environment variables. Example command line:
java -cp tinylog-api-2.1.2.jar:tinylog-impl-2.1.2.jar:diozero-core-0.13.jar:diozero-provider-pigpio-0.13.jar:pigpioj-java-2.4.jar:diozero-sampleapps-0.13.jar -DPIGPIOD_HOST=raspberrypi com.diozero.sampleapps.LEDTest 12
I am in the process of adding generic remote device access protocols to diozero, please see the diozero-remote-server and diozero-provider-remote projects. The idea is that support for these protocols can be developed for any device, including those that don’t run Java in particular the extremely cheap Wi-Fi connected ESP8266 and ESP32.
The code has been designed to be generic so as to support any communication channel and protocol. To switch between the different client implementations you currently need to modify the RemoteDeviceFactory class.
So far I have developed support for the following remote protocols:
|HTTP||JSON||Server, Client||GPIO (read and write), SPI. I2C support not yet implemented. Something like Server-sent Events would be required to support GPIO events.|
|WebSockets||JSON, Google Protobuf||JSON Server, JSON Client, Protobuf Client||GPIO (read, write and events), SPI. I2C support not yet implemented. Java Protobuf server not yet implemented.|
|MQTT||Google Protobuf||Server, Client||GPIO (read, write and events), SPI. I2C support not yet implemented.|
|Socket||VoodooSpark||Server, Client||GPIO (read, write and events). I2C support not yet implemented. SPI not currently supported by VoodooSpark.|
|Socket||pigpiod||Server||Client not yet ported to diozero-provider-remote.|
|USB||firmata||Arduino Server, Particle Spark Server||Client not yet ported to diozero-provider-remote.|
Performance is surprisingly good, I’ve been using my SSD1331Test application to check frames per second when rendering Game of Life iterations to an SSD1331 colour OLED display via SPI; I’ve not seen much difference between the various protocols. Performance is approximately half of that when run on the device itself.