Beispiel #1
0
        public static void Main()
        {
            var wifi = new NeonWifiDevice();
            //wifi.EnableDebugOutput = true;
            //wifi.EnableVerboseOutput = true;

            wifi.Booted += WifiOnBooted;  // or you can wait on the wifi.IsInitializedEvent
            //wifi.Error += WifiOnError;
            //wifi.ConnectionStateChanged += WifiOnConnectionStateChanged;

            //var apList = wifi.GetAccessPoints();
            //Debug.Print("Access points:");
            //foreach (var ap in apList)
            //{
            //    Debug.Print("ECN : " + ap.Ecn);
            //    Debug.Print("SSID : " + ap.Ssid);
            //    Debug.Print("RSSI : " + ap.Rssi);
            //    Debug.Print("MAC addr : " + ap.MacAddress);
            //    Debug.Print("Connection is : " + (ap.AutomaticConnectionMode ? "Automatic" : "Manual"));
            //}

            wifi.Connect("XXX","XXX");

            var sntp = new SntpClient(wifi, "time1.google.com");
            sntp.SetTime();

            var uri = new Uri("http://www.example.com");
            var httpClient = new HttpClient(wifi);
            var request = new HttpRequest(uri);
            request.Uri = uri;
            request.Headers.Add("Connection","Keep-Alive");
            request.ResponseReceived += HttpResponseReceived;
            httpClient.SendAsync(request);
            
            bool state = true;
            int iCounter = 0;
            while (true)
            {
                Hardware.UserLed.Write(state);
                state = !state;
                if (++iCounter == 10)
                {
                    Debug.Print("Current UTC time : " + DateTime.UtcNow);
                    iCounter = 0;
                }
                Thread.Sleep(500);
            }
        }
        public void Start()
        {
            _properties = (PropertyDictionary)DiContainer.Instance.Resolve(typeof(PropertyDictionary));

            DiContainer.Instance.Register(typeof(INetworkAdapter), typeof(NeonWifiDevice)).AsSingleton();
            _wifi = (NeonWifiDevice)DiContainer.Instance.Resolve(typeof(INetworkAdapter));
            Thread.Sleep(2000);

            //TODO: Get this, the node id, Verdant server, etc., from EWR.  Need to create a settings service.
            _wifi.Connect("CloudGate", "Escal8shun");

            _sntpClient = new SntpClient(_wifi, "time1.google.com");
            _sntpClient.SetTime();

            _properties.SetProperty(PropertyNames.IPAddressPropName, _wifi.StationIPAddress.ToString());
        }
Beispiel #3
0
        public static void Main()
        {
            var wifi = new NeonWifiDevice();
            //wifi.EnableDebugOutput = true;
            //wifi.EnableVerboseOutput = true;

            wifi.Booted += WifiOnBooted;  // or you can wait on the wifi.IsInitializedEvent

            wifi.Connect(SSID, PASSWD);

            var sntp = new SntpClient(wifi, "time1.google.com");
            sntp.SetTime();

            MobileServiceClient msc = new MobileServiceClient(wifi, ak16Uri, null, AzureAppKey);
            IMobileServiceTable tab = msc.GetTable("environment_measures");

            //try
            //{
            // Test a dummy insert for now
            MeasurementRow row = new MeasurementRow();
            row.DateTimeStamp = DateTime.Now;
            row.where = "here"; //Resources.GetString(Resources.StringResources.VanWie);
            row.what = "nothing";
            row.value = -1f;
            row.uom = " ";
            string surprise = tab.Insert(row); // Failing on this line
            Debug.Print(DateTime.Now.ToString("T") + " " + surprise);

            bool state = true;
            int iCounter = 0;
            while (true)
            {
                Hardware.UserLed.Write(state);
                state = !state;
                if (++iCounter == 10)
                {
                    Debug.Print("Current UTC time : " + DateTime.UtcNow);
                    iCounter = 0;
                }
                Thread.Sleep(500);
            }
        }
Beispiel #4
0
        public static void Main()
        {
            // For neon
            var wifi = new Esp8266WifiDevice(new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One), new OutputPort((Cpu.Pin)19, false), null);
            wifi.Connect("Xxxxx", "Xxxxx");

            var sntp = new SntpClient(wifi, "time1.google.com");
            sntp.SetTime();

            // You have to change this - the storage account does not exist and the key is not valid
            var account = new CloudStorageAccount("pdazurestoragedemo", "PblOktyRKcKQy+5qMe3doPcxzcUqKU38ZBTGCOs8g+10CamdApbJd1FDw2WTsZ8/k+LoUvCQsc4NPBZ0jY/9DA==");
            var blob = new BlobClient(wifi, account);

            var containerName = "cont3";

            // if needed...
            //blob.CreateContainer(containerName);

            var someBytes = new byte[256];
            for (int i = 0; i < someBytes.Length; ++i)
                someBytes[i] = (byte)i;
            blob.PutBlockBlob(containerName, "mybytes", someBytes);
        }
Beispiel #5
0
        // In order to create a truly robust long-running solution, you must combine the code below
        //   with proper use of a Watchdog Timer and exception handling on the wifi calls.
        // Hardware note: It has been our experience that to work at 115200 with the ESP8266 and NETMF, you need a 1024 byte serial buffer.
        //   Smaller serial buffers may result in portions of incoming TCP traffic being dropped, which can also break the protocol processing
        //   and result in hangs.

        public static void Main()
        {
            var port = new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One);
            var wifi = new Esp8266WifiDevice(port, _rfPower, null);
            // On Oxygen+Neon, you can use use new NeonWifiDevice() without providing a port or power pin definition

            // Enable echoing of commands
            wifi.EnableDebugOutput = true;
            // Enable dump of every byte sent or received (may introduce performance delays and can cause buffer overflow
            //   at low baud rates or with small serial buffers.
            //wifi.EnableVerboseOutput = true;

            Debug.Print("Access points:");
            var apList = wifi.GetAccessPoints();
            foreach (var ap in apList)
            {
                Debug.Print("ssid:" + ap.Ssid + "  ecn:" + ap.Ecn);
            }
            Debug.Print("-- end of list -------------");

#if CREATE_ACCESS_POINT
            wifi.Mode = OperatingMode.Both;
            wifi.ConfigureAccessPoint("serwifitest", "24681234", 5, Ecn.WPA2_PSK);
            wifi.EnableDhcp(OperatingMode.AccessPoint, true);
#else
            wifi.Mode = OperatingMode.Station;
#endif
            wifi.Connect("XXX", "XXX");

            Debug.Print("Station IP address : " + wifi.StationIPAddress.ToString());
            Debug.Print("Station MAC address : " + wifi.StationMacAddress);
            Debug.Print("Station Gateway address : " + wifi.StationGateway.ToString());
            Debug.Print("Station netmask : " + wifi.StationNetmask.ToString());

            Debug.Print("AP SSID : " + wifi.AccessPointSsid);
            Debug.Print("AP Password : "******"AP Channel : " + wifi.AccessPointChannel);
            Debug.Print("AP ECN : " + wifi.AccessPointEcn);

            Debug.Print("AP IP address : " + wifi.AccessPointIPAddress.ToString());
            Debug.Print("AP MAC address : " + wifi.AccessPointMacAddress);
            Debug.Print("AP Gateway address : " + wifi.AccessPointGateway.ToString());
            Debug.Print("AP netmask : " + wifi.AccessPointNetmask.ToString());

            var sntp = new SntpClient(wifi, "time1.google.com");
            // You should repeat this every day or so, to counter clock drift, or use .Start()
            // to update the clock against and SNTP server automatically in the background.
            sntp.SetTime();

            wifi.CreateServer(80, OnServerConnectionOpened);

            var httpClient = new HttpClient(wifi);
            var request = new HttpRequest(new Uri("http://www.example.com/"));
            request.ResponseReceived += HttpResponseReceived;
            httpClient.SendAsync(request);

            int iCounter = 0;
            bool state = true;
            while (true)
            {
                _userLed.Write(state);
                state = !state;
                ++iCounter;
                if (iCounter % 10 == 0)
                {
                    Debug.Print("Current UTC time : " + DateTime.UtcNow);
                }
                // Every 15 seconds
                if (iCounter % 30 == 0)
                {
#if CREATE_ACCESS_POINT
                    Debug.Print("Clients connected to this AP");
                    var clientList = wifi.GetConnectedClients();
                    foreach (var client in clientList)
                    {
                        Debug.Print("IP:" + client.IpAddress.ToString() + "  MAC:" + client.MacAddress);
                    }
                    Debug.Print("-- end of list -------------");
#endif
                    iCounter = 0;
                }
                Thread.Sleep(500);
            }
        }