Ejemplo n.º 1
0
        public async void Start()
        {
            MessageClient messageClient = App.Current.Resources["MessageClient"] as MessageClient;

            messageClient.DataReceived += messageClient_DataReceived;

            if (await messageClient.Start(IpAddress, PortNumber))
            {
                messageClient.SubscribeToData(Devices.PIBRELLA, Pibrella.OBJECT_GREEN_LED, Pibrella.DATA_LED_STATUS);
                messageClient.SubscribeToData(Devices.PIBRELLA, Pibrella.OBJECT_YELLOW_LED, Pibrella.DATA_LED_STATUS);
                messageClient.SubscribeToData(Devices.PIBRELLA, Pibrella.OBJECT_RED_LED, Pibrella.DATA_LED_STATUS);
                messageClient.SubscribeToData(Devices.PIBRELLA, Pibrella.OBJECT_BUTTON, Pibrella.DATA_BUTTON_STATUS);

                //messageClient.SubscribeToServerState(ServerStates.STATE_NETDUINO_ISCONNECTED);
                //messageClient.SubscribeToServerState(ServerStates.STATE_RASPBERRYPIB_ISCONNECTED);
                //messageClient.SubscribeToServerState(ServerStates.STATE_WINDOWSPHONE_ISCONNECTED);
                //messageClient.SubscribeToServerState(ServerStates.STATE_SURFACE_ISCONNECTED);
                //messageClient.SubscribeToServerState(ServerStates.STATE_VOLTAGE_CONTROL);

                messageClient.PublishCommand(Devices.PIBRELLA, Pibrella.OBJECT_GREEN_LED, Pibrella.COMMAND_TOGGLE_LED);
                messageClient.PublishCommand(Devices.PIBRELLA, Pibrella.OBJECT_YELLOW_LED, Pibrella.COMMAND_TOGGLE_LED);
                messageClient.PublishCommand(Devices.PIBRELLA, Pibrella.OBJECT_RED_LED, Pibrella.COMMAND_TOGGLE_LED);
                messageClient.PublishCommand(Devices.PIBRELLA, Pibrella.OBJECT_BUTTON, Pibrella.COMMAND_BUTTON_PRESSED);
            }
        }
Ejemplo n.º 2
0
        public static void Start(string ipAddress, int portNumber)
        {
            MessageClient messageClient = new MessageClient(Devices.WINDOWS_PHONE, HEARTBEAT_PERIOD_IN_MILLESECONDS);

            messageClient.DataReceived += client_DataReceived;

            Console.WriteLine("Remote console");
            Console.WriteLine("Hit a key to start client, hit [0,3] to send Pibrella commands, hit ESC to exit.");
            Console.ReadKey();

            messageClient.Start(ipAddress, portNumber);

            Console.WriteLine("Running.");

            messageClient.SubscribeToData(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_GREEN_LED, Pibrella.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_YELLOW_LED, Pibrella.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_RED_LED, Pibrella.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_BUTTON, Pibrella.DATA_BUTTON_STATUS);

            messageClient.PublishCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_GREEN_LED, Pibrella.COMMAND_TOGGLE_LED);
            messageClient.PublishCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_YELLOW_LED, Pibrella.COMMAND_TOGGLE_LED);
            messageClient.PublishCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_RED_LED, Pibrella.COMMAND_TOGGLE_LED);
            messageClient.PublishCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_BUTTON, Pibrella.COMMAND_BUTTON_PRESSED);

            bool running = true;

            while (running)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                if (keyInfo.KeyChar.Equals('0'))
                {
                    messageClient.SendCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_BUTTON, Pibrella.COMMAND_BUTTON_PRESSED, String.Empty);
                }
                if (keyInfo.KeyChar.Equals('1'))
                {
                    messageClient.SendCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_GREEN_LED, Pibrella.COMMAND_TOGGLE_LED, String.Empty);
                }
                else if (keyInfo.KeyChar.Equals('2'))
                {
                    messageClient.SendCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_YELLOW_LED, Pibrella.COMMAND_TOGGLE_LED, String.Empty);
                }
                else if (keyInfo.KeyChar.Equals('3'))
                {
                    messageClient.SendCommand(Devices.RASPBERRY_PI_B, Pibrella.OBJECT_RED_LED, Pibrella.COMMAND_TOGGLE_LED, String.Empty);
                }
                else if (keyInfo.Key == ConsoleKey.Escape)
                {
                    running = false;
                    break;
                }
            }

            Console.WriteLine("Stopped.");

            messageClient.Stop();
        }
Ejemplo n.º 3
0
        public static void Start(string ipAddress, int portNumber)
        {
            MessageClient messageClient = new MessageClient(Devices.WINDOWS_PHONE, HEARTBEAT_PERIOD_IN_MILLESECONDS);

            messageClient.DataReceived += client_DataReceived;

            Console.WriteLine("Remote console");
            Console.WriteLine("Hit a key to start client, hit [0,3] to send MCP4921 commands, hit ESC to exit.");
            Console.ReadKey();

            messageClient.Start(ipAddress, portNumber);

            Console.WriteLine("Running.");

            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_ANALOG_DATA, MCP4921.DATA_ANALOG_VALUE);
            messageClient.PublishCommand(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_DIGITAL_DATA, MCP4921.COMMAND_CONVERT);

            bool running = true;

            while (running)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                if (keyInfo.KeyChar.Equals('0'))
                {
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_DIGITAL_DATA, MCP4921.COMMAND_CONVERT, "10");
                }
                if (keyInfo.KeyChar.Equals('1'))
                {
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_DIGITAL_DATA, MCP4921.COMMAND_CONVERT, "30");
                }
                else if (keyInfo.KeyChar.Equals('2'))
                {
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_DIGITAL_DATA, MCP4921.COMMAND_CONVERT, "60");
                }
                else if (keyInfo.KeyChar.Equals('3'))
                {
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, MCP4921.OBJECT_DIGITAL_DATA, MCP4921.COMMAND_CONVERT, "90");
                }
                else if (keyInfo.Key == ConsoleKey.Escape)
                {
                    running = false;
                    break;
                }
            }

            Console.WriteLine("Stopped.");

            messageClient.Stop();
        }
Ejemplo n.º 4
0
        public static void Start(string ipAddress, int portNumber)
        {
            MessageClient messageClient = new MessageClient(Devices.WINDOWS_PHONE);

            messageClient.DataReceived += client_DataReceived;

            Console.WriteLine("Remote console");

            Console.WriteLine("Hit a key to start client, hit [0,3] to send Photon commands, hit ESC to exit.");
            Console.ReadKey();

            messageClient.Start(ipAddress, portNumber);

            Console.WriteLine("Running.");

            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_SENSOR, Photon.DATA_SENSOR_HUMIDITY);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_SENSOR, Photon.DATA_SENSOR_TEMPERATURE);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_BOARD_LED, Photon.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_GREEN_LED, Photon.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_RED_LED, Photon.DATA_LED_STATUS);

            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.DATA_RGB_RED);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.DATA_RGB_GREEN);
            messageClient.SubscribeToData(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.DATA_RGB_BLUE);

            messageClient.PublishCommand(Devices.PHOTON_B, Photon.OBJECT_GREEN_LED, Photon.COMMAND_TOGGLE_LED);
            messageClient.PublishCommand(Devices.PHOTON_B, Photon.OBJECT_RED_LED, Photon.COMMAND_TOGGLE_LED);

            messageClient.PublishCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_RED);
            messageClient.PublishCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_GREEN);
            messageClient.PublishCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_BLUE);

            bool running = true;

            while (running)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                double random = new Random().NextDouble();

                if (keyInfo.KeyChar.Equals('0'))
                {
                    messageClient.SendCommand(Devices.PHOTON_B, Photon.OBJECT_BOARD_LED, Photon.COMMAND_TOGGLE_LED, String.Empty);
                }
                if (keyInfo.KeyChar.Equals('1'))
                {
                    int rgbRed = (int)(random * 255);
                    messageClient.SendCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_RED, rgbRed.ToString());
                }
                if (keyInfo.KeyChar.Equals('2'))
                {
                    int rgbGreen = (int)(random * 255);
                    messageClient.SendCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_GREEN, rgbGreen.ToString());
                }
                if (keyInfo.KeyChar.Equals('3'))
                {
                    int rgbBlue = (int)(random * 255);
                    messageClient.SendCommand(Devices.PHOTON_B, Photon.OBJECT_RGB_LED, Photon.COMMAND_SET_RGB_BLUE, rgbBlue.ToString());
                }
                else if (keyInfo.Key == ConsoleKey.Escape)
                {
                    running = false;
                    break;
                }
            }

            Console.WriteLine("Stopped.");

            messageClient.Stop();
        }
Ejemplo n.º 5
0
        public static void Start(string ipAddress, int portNumber)
        {
            const int HEARTBEAT_PERIOD_IN_MILLESECONDS = 10000;

            bool redLedStatus   = false;
            bool greenLedStatus = false;

            MessageClient messageClient = new MessageClient(Devices.WINDOWS_PHONE, HEARTBEAT_PERIOD_IN_MILLESECONDS);

            messageClient.DataReceived += client_DataReceived;

            Console.WriteLine("Remote console");
            Console.WriteLine("Hit a key to start client, hit [0,2] to send Netduino command, hit ESC to exit.");
            Console.ReadKey();

            messageClient.Start(ipAddress, portNumber);

            Console.WriteLine("Running.");

            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_BOARD_LED, LEDs.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_BUTTON, LEDs.DATA_BUTTON_STATUS);
            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_SENSOR, LEDs.DATA_SENSOR_RANDOM);

            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_RED_LED, LEDs.DATA_LED_STATUS);
            messageClient.SubscribeToData(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_GREEN_LED, LEDs.DATA_LED_STATUS);

            messageClient.PublishCommand(Devices.ALL, Pibrella.OBJECT_BUTTON, Pibrella.COMMAND_BUTTON_PRESSED);
            messageClient.PublishCommand(Devices.ALL, Pibrella.OBJECT_RED_LED, Pibrella.COMMAND_TOGGLE_LED);
            messageClient.PublishCommand(Devices.ALL, Pibrella.OBJECT_GREEN_LED, Pibrella.COMMAND_TOGGLE_LED);

            bool running = true;

            while (running)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                if (keyInfo.KeyChar.Equals('0'))
                {
                    redLedStatus = !redLedStatus;
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_BUTTON, LEDs.COMMAND_BUTTON_PRESSED, LEDs.CONTENT_BUTTON_PRESSED);
                }
                if (keyInfo.KeyChar.Equals('1'))
                {
                    redLedStatus = !redLedStatus;
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_RED_LED, LEDs.COMMAND_TOGGLE_LED, redLedStatus ? LEDs.CONTENT_LED_STATUS_ON : LEDs.CONTENT_LED_STATUS_OFF);
                }
                else if (keyInfo.KeyChar.Equals('2'))
                {
                    greenLedStatus = !greenLedStatus;
                    messageClient.SendCommand(Devices.NETDUINO_3_WIFI, LEDs.OBJECT_GREEN_LED, LEDs.COMMAND_TOGGLE_LED, greenLedStatus ? LEDs.CONTENT_LED_STATUS_ON : LEDs.CONTENT_LED_STATUS_OFF);
                }
                if (keyInfo.Key == ConsoleKey.Escape)
                {
                    running = false;
                    break;
                }
            }

            Console.WriteLine("Stopped.");

            messageClient.Stop();
        }