static void Main(string[] args) { try { // create a RestfulDeviceService used to communicate with the DeviceHive cloud // insert your assigned DeviceHive service URL here var service = new RestfulDeviceService("http://pg.devicehive.com/api"); // create a DeviceHive network where our device will reside var network = new Network("VirtualLed Sample Network", "A DeviceHive network for VirtualLed sample"); // create a DeviceHost used to run our device var deviceHost = new DeviceHost(service, network); // create an instance of virtual LED device and add it to the host var led = new VirtualLedDevice(); deviceHost.AddDevice(led); // start the host - it will register the device and start polling commands deviceHost.Start(); // wait for console key press and then stop the host Console.WriteLine("Device is now running, press any key to stop..."); Console.ReadKey(); deviceHost.Stop(); } catch (Exception ex) { // handle the error Console.WriteLine("Error: " + ex); Console.ReadKey(); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="client">Associated DeviceHive device client. Use any custom or default <see cref="RestfulDeviceService"/> implementation.</param> /// <param name="network">Associated DeviceHive network object (optional). If specified network is not found in the DeviceHive service, it will be automatically created.</param> public DeviceHost(IDeviceService client, Network network) { if (client == null) throw new ArgumentNullException("client"); DeviceClient = client; Network = network; }
/// <summary> /// Initializes all device properties. /// </summary> /// <param name="id">Device unique identifier (device-assigned).</param> /// <param name="key">Device key. Device key is a private value used for device authentication in DeviceHive.</param> /// <param name="name">Device name.</param> /// <param name="status">Device status.</param> /// <param name="network">Associated device network object.</param> /// <param name="deviceClass">Associated device class object.</param> public Device(Guid? id, string key, string name, string status, Network network, DeviceClass deviceClass) { Id = id; Key = key; Name = name; Status = status; Network = network; DeviceClass = deviceClass; }
private static void Main() { try { // initialize logger log4net.Config.XmlConfigurator.Configure(); // create a RestfulDeviceService used to communicate with the DeviceHive cloud // insert your assigned DeviceHive service URL here using (var deviceService = new RestfulDeviceService("http://localhost/DeviceHive.API")) { // create a DeviceHive network where our gateway will reside var network = new Network("Gateway Sample Network", "A DeviceHive network for Gateway sample"); // create gateway service var gatewayService = new GatewayService(deviceService, network); // create connection to device through COM port and add it to the gateway // insert your COM port name here var serialPort = new SerialPort("COM3") {ReadTimeout = 1000, WriteTimeout = 1000, BaudRate = 9600}; var serialPortConnection = new SerialPortBinaryConnection(serialPort); gatewayService.DeviceConnectionList.Add(serialPortConnection); // start gateway gatewayService.Start(); // wait for console key press and then dispose gateway service Console.WriteLine("Gateway is now running, press any key to stop..."); Console.ReadKey(); gatewayService.Stop(); } } catch (Exception ex) { // handle the error Console.WriteLine("Error: " + ex); Console.ReadKey(); } }
static void Main(string[] args) { try { // initialize logger log4net.Config.XmlConfigurator.Configure(); // create a RestfulDeviceService used to communicate with the DeviceHive cloud // insert your assigned DeviceHive service URL here using (var service = new RestfulDeviceService("http://localhost/DeviceHive.API")) { // create a DeviceHive network where our device will reside var network = new Network("VirtualLed Sample Network", "A DeviceHive network for VirtualLed sample"); // or use network with network key //var network = new Network("Network WPNBEP", "Playground Network", "%NETWORK_KEY%"); // create a DeviceHost used to run our device var deviceHost = new DeviceHost(service, network); // create an instance of virtual LED device and add it to the host var led = new VirtualLedDevice(); deviceHost.AddDevice(led); // start the host - it will register the device and start polling commands deviceHost.Start(); // wait for console key press and then stop the host Console.WriteLine("Device is now running, press any key to stop..."); Console.ReadKey(); deviceHost.Stop(); } } catch (Exception ex) { // handle the error Console.WriteLine("Error: " + ex); Console.ReadKey(); } }
/// <summary> /// Initializes all device properties. /// </summary> /// <param name="id">Device unique identifier (device-assigned).</param> /// <param name="key">Device key. Device key is a private value used for device authentication in DeviceHive.</param> /// <param name="name">Device name.</param> /// <param name="status">Device status.</param> /// <param name="data">Device data, an optional json token used to describe additional device information.</param> /// <param name="network">Associated device network object (optional).</param> /// <param name="deviceClass">Associated device class object.</param> public Device(Guid? id, string key, string name, string status, JToken data, Network network, DeviceClass deviceClass) : this(id, key) { Name = name; Status = status; Data = data; Network = network; DeviceClass = deviceClass; }