/** entry point of the application */
        public static void Main()
        {
            wifi = new WiFiESP12F(IO.Port1);
            wifi.reset();
            Thread.Sleep(1000);
            wifi.setWifiMode(WiFiESP12F.wifiMode.SOFTAP);
            wifi.setAP("WifiTest", "Password1", 1, WiFiESP12F.SecurityType.WPA_WPA2_PSK);
            Thread.Sleep(1000);            // Required after calling setAP



#if (UDP)
            wifi.startUDP(4, "192.168.4.2", 11000, 11001);
#endif
#if (TCPServer)
            wifi.openTCPServer(11001);
#endif
#if (TCP)
            wifi.startTCP(0, "192.168.4.2", 11000);
#endif

            /* temporary array */
            byte[] scratch = new byte[1];


            /* loop forever */

            while (true)
            {
                /* read bytes out of uart */
                if (wifi.processInput())
                {
                    /*transfer processed data to cache*/
                    cacheSize = wifi.transferDataCache(_cache);
                    for (int j = 0; j < cacheSize; j++)
                    {
                        PushByte(_cache[j]);
                    }
                }

                /* if there are bufferd bytes echo them back out */
                if (_txCnt > 0)
                {
                    scratch = new byte[_txCnt];
                    PopTX(scratch);


#if (UDP)
                    wifi.sendUDP(4, scratch);
#endif
#if (TCPServer || TCP)
                    wifi.sendTCP(0, scratch); //The '0' id assumes you only have one connection on the TCP server. A list of connections can be obtained using 'AT+CIPSTATUS'.
#endif
                }
            }
        }
Esempio n. 2
0
        /** entry point of the application */
        public static void Main()
        {
            /* Iniitalize wifi module */
            //_wifi.enableDebugPrints(false);
            Debug.Print("Init Start!");
            _wifi.reset();
            Thread.Sleep(1000);
            Thread.Sleep(1000);
            _wifi.setWifiMode(WiFiESP12F.wifiMode.SOFTAP_STATION);
            Thread.Sleep(1000);
            _wifi.setAP("G_WifiModule", "Chickens", 1, WiFiESP12F.SecurityType.WPA_WPA2_PSK);
            _wifi.startUDP(4, "192.168.4.2", 11000, 11001);
            Debug.Print("Init Done!");
            _wifi.test();       //This is done to skip the cipstart... need to learn more about this

            int  counter      = 0;
            bool state        = true;
            bool lastHeroRead = false;

            while (true)
            {
                bool button = _HEROButton.Read();
                if (button)
                {
                    counter++;
                    if (counter >= 100)
                    {
                        state = !state;
                        _wifi.enableDebugPrints(state);
                        Debug.Print(state ? "Prints Enabled" : "Prints Disabled");
                        counter = 0;
                    }
                }
                else
                {
                    counter = 0;
                }

                if (button && !lastHeroRead)
                {
                    /* Test the various modes */
                    String APIP      = _wifi.getAccessPointIP();
                    String StationIP = _wifi.getStationIP();
                    Debug.Print("IP : " + StationIP + " || " + APIP);
                }
                lastHeroRead = button;

                Thread.Sleep(10);
            }
        }