Exemplo n.º 1
0
        private static void GprsProvider_GprsIpAppsBearerStateChanged(bool isOpen)
        {
            if (isOpen)
            {
                // launch a new thread to get time and location from network
                new Thread(() =>
                {
                    Thread.Sleep(1000);

                    LocationAndTime lt = SIM800H.GetTimeAndLocation();

                    if (lt.ErrorCode == 0)
                    {
                        // request successfull
                        Debug.Print("Network time " + lt.DateTime.ToString() + " GMT");
                        Debug.Print("Location http://www.bing.com/maps/?v=2&form=LMLTSN&cp=" + lt.Latitude.ToString() + "~" + lt.Longitude.ToString() + "&lvl=17&sty=r&encType=1");
                    }
                    else
                    {
                        // failed to retrieve time and location from network
                        Debug.Print("### Failed to retrieve time and location from network. Error code: " + lt.ErrorCode.ToString() + " ###");
                    }
                }).Start();
            }
        }
Exemplo n.º 2
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial device
            SerialDevice sim800SerialDevice = SerialDevice.FromId("COM2");

            // SIM800H signal for "power key"
            GpioPin sim800PowerKey = GpioController.GetDefault().OpenPin(0 * 1 + 10, GpioSharingMode.Exclusive);

            sim800PowerKey.SetDriveMode(GpioPinDriveMode.Output);

            Console.WriteLine("... Configuring SIM800H ...");

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, ref sim800SerialDevice);

            // async call to power on module
            // in this example we are setting up a callback on a separate method
            SIM800H.PowerOnAsync(PowerOnCompleted);
            Console.WriteLine("... Power on sequence started ...");
        }
Exemplo n.º 3
0
        private static void GprsProvider_GprsIpAppsBearerStateChanged(bool isOpen)
        {
            if (isOpen)
            {
                // launch a new thread to update the RTC from the NTP server
                new Thread(() =>
                {
                    Debug.Print("... Going into power down...");
                    Thread.Sleep(1000);
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Power Off: device will be powered off
                    // The following call powers off the module completely, only a power ON cycle - PowerOnAsync(...) - will be
                    // able to wake up the module.
                    // After the following call you should be able to read a power consumption of approximately 60uA.
                    SIM800H.PowerOff();

                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Flight Mode: disable tx and rx RF circuits
                    // The following call powers down the module to flight mode, writing to UART will wakes up the module
                    // After the following call you should be able to read a power consumption of approximately 1.02mA
                    //SIM800H.SetPhoneFuncionality(PhoneFuncionality.FligthMode);

                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Minimum: minimum current consumption, RF and SIM are off
                    // The following call powers down the module to minimum funcionality, writing to UART will wakes up the module
                    // After the following call you should be able to read a power consumption of approximately 0.796mA
                    //SIM800H.SetPhoneFuncionality(PhoneFuncionality.Minimum);
                }).Start();
            }
        }
Exemplo n.º 4
0
        static void UpdateRTCFromNetwork()
        {
            SIM800H.SntpClient.SyncNetworkTimeAsync("time.nist.gov", TimeSpan.Zero, (ar) =>
            {
                // update RTC only if update was successful
                if (((SyncNetworkTimeAsyncResult)ar).Result == SyncResult.SyncSuccessful)
                {
                    // get current date time and update RTC
                    DateTime rtcValue = SIM800H.GetDateTime();
                    // set framework date time
                    Utility.SetLocalTime(rtcValue);

                    // done here, dispose SNTP client to free up memory
                    SIM800H.SntpClient.Dispose();
                    SIM800H.SntpClient = null;

                    new Thread(() =>
                    {
                        Thread.Sleep(1000);

                        // start doing the thing with IoT Hub...
                        StartDeviceOperation();
                    }).Start();
                }
                else
                {
                    Debug.Print("### failed to get time from NTP server ###");
                }
            });
        }
Exemplo n.º 5
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial port
            SerialPort sim800SerialPort = new SerialPort("COM2");

            // SIM800H signal for "power key"
            OutputPort sim800PowerKey = new OutputPort(Cpu.Pin.GPIO_Pin6, false);

            Microsoft.SPOT.Debug.Print("... Configuring SIM800H ...");

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, sim800SerialPort);

            // async call to power on module
            // in this example we are setting up a callback on a separate method
            SIM800H.PowerOnAsync(PowerOnCompleted);
            Microsoft.SPOT.Debug.Print("... Power on sequence started ...");
        }
Exemplo n.º 6
0
        public static void Main()
        {
            InitializeSIM800H();

            // loop forever and output available RAM each 5 seconds
            while (true)
            {
                Thread.Sleep(5000);

                // output signal RSSI
                Console.WriteLine("Network signal strength is " + SIM800H.RetrieveSignalStrength().GetSignalStrengthDescription());
            }
            ;
        }
Exemplo n.º 7
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial device
            SerialDevice sim800SerialDevice = SerialDevice.FromId("COM2");

            // SIM800H signal for "power key"
            GpioPin sim800PowerKey = GpioController.GetDefault().OpenPin(0 * 1 + 10, GpioSharingMode.Exclusive);

            sim800PowerKey.SetDriveMode(GpioPinDriveMode.Output);

            Console.WriteLine("... Configuring SIM800H ...");

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, ref sim800SerialDevice);

            // set event handler for SMS ready
            SIM800H.SmsReady += SIM800H_SmsReady;

            // async call to power on module
            // in this example we are implementing the callback in line
            SIM800H.PowerOnAsync((ar) =>
            {
                // check result
                if (((PowerOnAsyncResult)ar).Result == PowerStatus.On)
                {
                    Console.WriteLine("... Power on sequence completed...");
                }
                else
                {
                    // something went wrong...
                    Console.WriteLine("### Power on sequence FAILED ###");
                }
            }
                                 );

            Console.WriteLine("... Power on sequence started ...");
        }
Exemplo n.º 8
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial port
            SerialPort sim800SerialPort = new SerialPort("COM2");

            // SIM800H signal for "power key"
            OutputPort sim800PowerKey = new OutputPort(Cpu.Pin.GPIO_Pin6, false);

            Microsoft.SPOT.Debug.Print("... Configuring SIM800H ...");

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, sim800SerialPort);

            // set event handler for SMS ready
            SIM800H.SmsReady += SIM800H_SmsReady;

            // async call to power on module
            // in this example we are implementing the callback in line
            SIM800H.PowerOnAsync((ar) =>
            {
                // check result
                if (((PowerOnAsyncResult)ar).Result == PowerStatus.On)
                {
                    Debug.Print("... Power on sequence completed...");
                }
                else
                {
                    // something went wrong...
                    Debug.Print("### Power on sequence FAILED ###");
                }
            }
                                 );

            Microsoft.SPOT.Debug.Print("... Power on sequence started ...");
        }
Exemplo n.º 9
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial device
            SerialDevice sim800SerialDevice = SerialDevice.FromId("COM2");

            // SIM800H signal for "power key"
            GpioPin sim800PowerKey = GpioController.GetDefault().OpenPin(0 * 1 + 10, GpioSharingMode.Exclusive);

            sim800PowerKey.SetDriveMode(GpioPinDriveMode.Output);

            Console.WriteLine("... Configuring SIM800H ...");

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, ref sim800SerialDevice);

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // add event handler to be aware of GPRS network registration status changes
            SIM800H.GprsNetworkRegistrationChanged += SIM800H_GprsNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // because we need Internet connection the access point configuration (APN) is mandatory
            // the configuration depends on what your network operator requires
            // it may be just the access point name or it may require an user and password too
            // AccessPointConfiguration class provides a number of convenient options to create a new APN configuration
            SIM800H.AccessPointConfiguration = AccessPointConfiguration.Parse(APNConfigString);

            // async call to power on module
            // in this example we are setting up a callback on a separate method
            SIM800H.PowerOnAsync(PowerOnCompleted);
            Console.WriteLine("... Power on sequence started ...");
        }
Exemplo n.º 10
0
        static void InitializeSIM800H()
        {
            // initialization of the module is very simple
            // we just need to pass a serial port and an output signal to control the "power key" signal

            // SIM800H serial port
            SerialPort sim800SerialPort = new SerialPort("COM2");

            // SIM800H signal for "power key"
            OutputPort sim800PowerKey = new OutputPort(Cpu.Pin.GPIO_Pin6, false);

            Microsoft.SPOT.Debug.Print("... Configuring SIM800H ...");

            // configure SIM800H device
            SIM800H.Configure(sim800PowerKey, sim800SerialPort);

            // add event handler to be aware of network registration status changes
            SIM800H.GsmNetworkRegistrationChanged += SIM800H_GsmNetworkRegistrationChanged;

            // add event handler to be aware of GPRS network registration status changes
            SIM800H.GprsNetworkRegistrationChanged += SIM800H_GprsNetworkRegistrationChanged;

            // it's wise to set this event handler to get the warning conditions from the module in case of under-voltage, over temperature, etc.
            SIM800H.WarningConditionTriggered += SIM800H_WarningConditionTriggered;

            // because we need Internet connection the access point configuration (APN) is mandatory
            // the configuration depends on what your network operator requires
            // it may be just the access point name or it may require an user and password too
            // AccessPointConfiguration class provides a number of convenient options to create a new APN configuration
            SIM800H.AccessPointConfiguration = AccessPointConfiguration.Parse(APNConfigString);

            // async call to power on module
            // in this example we are setting up a callback on a separate method
            SIM800H.PowerOnAsync(PowerOnCompleted);
            Microsoft.SPOT.Debug.Print("... Power on sequence started ...");
        }
Exemplo n.º 11
0
        static void UpdateRTCFromNetwork()
        {
            Console.WriteLine("... requesting time from NTP server ...");

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // the following code block uses an async call to SNTP client which should be OK for most of the use scenarios
            // check an alternative in the code block commented bellow

            SIM800H.SntpClient.SyncNetworkTimeAsync("pool.ntp.org", TimeSpan.Zero, (ar) =>
            {
                // update RTC only if update was successful
                if (((SyncNetworkTimeAsyncResult)ar).Result == SyncResult.SyncSuccessful)
                {
                    // get current date time and update RTC
                    DateTime rtcValue = SIM800H.GetDateTime();
                    // set framework date time
                    Rtc.SetSystemTime(rtcValue);

                    Console.WriteLine("!!! new time from NTP server: " + rtcValue.ToString());

                    // done here, dispose SNTP client to free up memory
                    SIM800H.SntpClient.Dispose();
                    SIM800H.SntpClient = null;
                }
                else
                {
                    Console.WriteLine("### failed to get time from NTP server ###");
                }
            });

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // if your network connection is not that good and you definitely need a valid RTC better do this inside a try/catch AND using a retry strategy
            // the implementation bellow uses a synchronous call to SNTP client
            // for the simplest async call see the

            //byte retryCounter = 0;

            //while (retryCounter <= 3)
            //{
            //    try
            //    {
            //        var result = SIM800H.SntpClient.SyncNetworkTimeAsync("time.nist.gov", TimeSpan.Zero).End();

            //        // check result
            //        if (result == SyncResult.SyncSuccessful)
            //        {
            //            // get current date time and update RTC
            //            DateTime rtcValue = SIM800H.GetDateTime();
            //            // set framework date time
            //            Rtc.SetSystemTime(rtcValue);

            //            Console.WriteLine("!!! new time from NTP server: " + rtcValue.ToString());

            //            // done here, dispose SNTP client to free up memory
            //            SIM800H.SntpClient.Dispose();
            //            SIM800H.SntpClient = null;

            //            return;
            //        }
            //        else
            //        {
            //            Console.WriteLine("### failed to get time from NTP server ###");
            //        }
            //    }
            //    catch
            //    {
            //        // failed updating RTC
            //        // flag this
            //    }

            //    // add retry
            //    retryCounter++;

            //    // progressive wait 15*N seconds before next retry
            //    Thread.Sleep(15000 * retryCounter);
            //}
        }