Example #1
0
 internal WifiSocket(Esp8266WifiDevice device, int iSocket, string hostname, int port, bool fTcp)
 {
     _parent = device;
     _iSocket = iSocket;
     _hostname = hostname;
     _port = port;
     _fTcp = fTcp;
 }
Example #2
0
 internal WifiSocket(Esp8266WifiDevice device, int iSocket, int port)
 {
     _parent = device;
     _iSocket = iSocket;
     _port = port;
     _hostname = null;
     _fTcp = true; // TEMP CODE
 }
Example #3
0
 internal WifiSocket(Esp8266WifiDevice device, int iSocket, int port)
 {
     _parent   = device;
     _iSocket  = iSocket;
     _port     = port;
     _hostname = null;
     _fTcp     = true; // TEMP CODE
 }
Example #4
0
 internal WifiSocket(Esp8266WifiDevice device, int iSocket, string hostname, int port, bool fTcp)
 {
     _parent   = device;
     _iSocket  = iSocket;
     _hostname = hostname;
     _port     = port;
     _fTcp     = fTcp;
 }
Example #5
0
        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.Mode = 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);
            }
        }
Example #6
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);
        }
Example #7
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);
            }
        }