Esempio n. 1
0
void bringUpWifi()
{
    unsigned triesBeforeChipReset = 2000;
    unsigned count = 0;
    while(!wifiConnected)
    {
        // Start by putting chip in known state
        esp.enable();
        delay(500);
        hardResetEspChip();
        delay(1000);
        esp.reset();
        delay(500);
        while(!esp.ready())
        {
            digitalWrite(HEART_BEAT_LED, HIGH);
            delay(1000);
            digitalWrite(HEART_BEAT_LED, LOW);
            delay(1000);
            if(count >= 3)
            {
                debugSerial.println("ARDUINO: Resetting ESP chip");
                esp.enable();
                delay(500);
                hardResetEspChip();
                delay(1000);
                esp.reset();
                delay(500);
                count = 0;
            }

            count++;
        }


        /*setup wifi*/
        debugSerial.println("ARDUINO: Setting up wifi");
        esp.wifiConnect(SSID,PASSWORD);
        // We should chill here until we get a wifi connection
        while(!wifiConnected && (count < triesBeforeChipReset) )
        {
            esp.process();
            delay(100);
            ++count;
        }
        count = 0;
    }
}
void WifiBegin(short isCiao) {
	espSerial.begin(9600);
	if(espSerial.ping()!=1) {
		espSerial.println("DBG: esp not found");
		while(1);
	}
	else {
		//espSerial.println("device found");
	}
	//put GPIO control here !!!
	esp.enable();
	delay(1000);
	esp.reset();
	delay(1000);
	while(!esp.ready());
	if (isCiao == 0)
		esp.wifiCb.attach(&wifiCb);

	espSerial.println("\nDBG: UnoWiFi Start");
}