...
Tip |
---|
You could use the "RaspberryPI" as Server |
Complete source
Code Block |
---|
import br.com.criativasoft.opendevice.core.SimpleDeviceManager; import br.com.criativasoft.opendevice.core.connection.Connections; import br.com.criativasoft.opendevice.core.model.Device; import br.com.criativasoft.opendevice.core.model.DeviceListener; import br.com.criativasoft.opendevice.core.model.DeviceType; public class RestControlDemo extends SimpleDeviceManager implements DeviceListener { public static void main(String[] args) throws Exception { new RestControlDemo(); } public RestControlDemo() throws Exception { Device led = new Device(1, DeviceType.DIGITAL); // setup connection with arduino/hardware addOutput(Connections.out.usb()); // Connect to first USB port available // Configure a Rest interface for receiving commands over HTTP addInput(Connections.in.rest(8181)); addListener(this); // monitor changes on devices connect(); addDevice(led); } // ------------- DeviceListener Impl -------------------------- // ------------------------------------------------------------ @Override public void onDeviceChanged(Device device) { System.out.println("DeviceChanged = " + device); } } |
Add Dependency:
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency>
<groupId>br.com.criativasoft.opendevice</groupId>
<artifactId>opendevice-rest-ws-server</artifactId>
<version>${opendevice-version}</version>
</dependency> |
Run the class and and open your browser in:
...