コード例 #1
0
ファイル: Program.cs プロジェクト: c-born/serialwifi
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: c-born/serialwifi
        public static void Main()
        {
            var port = new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One);
            var wifi = new Esp8266WifiDevice(port, _rfPower, null);

            wifi.EnableDebugOutput = true;
            //wifi.EnableVerboseOutput = true;

            wifi.SetOperatingMode(OperatingMode.Station);
            wifi.Connect("XXX", "XXX");

            Debug.Print("Version before update : ");
            foreach (var line in wifi.Version)
            {
                Debug.Print(line);
            }
            Debug.Print("------------------------");

            wifi.Update((progress) => { Debug.Print("Update progress : " + progress); });

            Debug.Print("Version after update : ");
            foreach (var line in wifi.Version)
            {
                Debug.Print(line);
            }
            Debug.Print("------------------------");

            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);
                    iCounter = 0;
                }
                Thread.Sleep(500);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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.

        static void Main()
        {
            _rfPower = GpioController.GetDefault().OpenPin(5);
            _rfPower.SetDriveMode(GpioPinDriveMode.Output);
            _rfPower.Write(GpioPinValue.High);

            _userLed = GpioController.GetDefault().OpenPin(45);
            _userLed.SetDriveMode(GpioPinDriveMode.Output);

            var port = UartController.FromName(SC20100.UartPort.Uart8);

            port.SetActiveSettings(115200, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);

            var wifi = new Esp8266WifiDevice(port, _rfPower, null);

            // Enable echoing of commands
            wifi.EnableDebugOutput = false;


            Debug.WriteLine("--------------------------------");
            Debug.WriteLine("----Esp 8266 Wifi TinyClr 2 ----");
            Debug.WriteLine("--------------------------------");
            wifi.Connect("valoninet", "valoni1234567");


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

            Thread.Sleep(1000);

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

            sntp.SetTime();

            int iCounter = 0;

            bool state = true;

            while (true)
            {
                state = !state;

                if (state)
                {
                    _userLed.Write(GpioPinValue.High);
                }
                else
                {
                    _userLed.Write(GpioPinValue.Low);
                }

                ++iCounter;
                if (iCounter % 10 == 0)
                {
                    Debug.WriteLine("Current UTC time : " + DateTime.UtcNow);
                    Debug.WriteLine("------------------------");
                }
                // Every 15 seconds

                Thread.Sleep(500);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: zsvanderlaan/serialwifi
        public static void Main()
        {
            var port = new SerialPort(GHI.Pins.FEZCobraII.Socket5.SerialPortName, 115200, Parity.None, 8, StopBits.One);
            var wifi = new Esp8266WifiDevice(port, null, null);

            wifi.EnableDebugOutput   = false;
            wifi.EnableVerboseOutput = false;

            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 -------------");

            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());

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

            sntp.SetTime();

            wifi.CreateServer(80, OnServerConnectionOpened);

            var httpClient = new HttpClient(wifi);
            //var request = new HttpRequest(new Uri("http://www.example.com/"));
            var request =
                new HttpRequest(new Uri("http://www.webservicex.net/uszip.asmx/GetInfoByAreaCode?USAreaCode=919"));

            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);
            }
        }