Ejemplo n.º 1
0
        public void didFinishLaunching()
        {
            NetworkInterface NI = NetworkInterface.GetAllNetworkInterfaces()[0];
            NDLogger.Log("Network IP " + NI.IPAddress.ToString(), LogLevel.Verbose);

            xbeeCoordinator = new XBeeCoordinator(createSerialPortWithName(SerialPorts.COM1));

            xbeeCoordinator.BytesReadFromSerial += new BytesReadFromSerialEventHandler(BytesReadFromSerialHandler);
            xbeeCoordinator.FrameDroppedByChecksum += new FrameDroppedByChecksumEventHandler(FrameDroppedByChecksumHandler);
            xbeeCoordinator.StartListen();

            upstreamMQTT = new NDMQTT();
            try
            {
                Configuration.MQTT = NDMQTTConfiguration.ReadFromFile(@"\SD\\mqtt_configuration.csv");
                startMQTT();
            }
            catch
            {
            }

            this.LocalAccessService.DataSource = this;
            this.LocalAccessService.Start();
            this.LocalAccessService.MqttConfigurationReceived += LocalAccessService_MqttConfigurationReceived;

            // setup our interrupt port (on-board button)
            onboardButton = new InterruptPort((Cpu.Pin)0x15, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);

            // assign our interrupt handler
            onboardButton.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

            discoveryService = new XBeeDiscoveryService(xbeeCoordinator);
            discoveryService.RemoteDeviceFound += new RemoteDeviceFoundEventHandler(OnRemoteXBeeFound);
            discoveryService.Discover();

            onboardLED.Write(false);
        }
Ejemplo n.º 2
0
        // the interrupt handler for the button
        void button_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            if (upstreamMQTT.IsConnected)
            {
                try
                {
                    upstreamMQTT.UnsubscribeFromEvents(new String[] { Configuration.MQTT.SensorDataTopic });
                }
                catch
                {
                    NDLogger.Log("MQTT unsubscribe exception!", LogLevel.Verbose);
                }

                upstreamMQTT.Disconnect();
                upstreamMQTT = null;
                NDLogger.Log("MQTT connection cancelled", LogLevel.Verbose);
            }
            else
            {
                try
                {
                    startMQTT();
                }
                catch
                {
                    NDLogger.Log("MQTT start exception!", LogLevel.Verbose);
                }
            }
        }