Ejemplo n.º 1
0
int WiFiCmdRobot::WiFiCmdRobot_begin() {
  
    int conID = DWIFIcK::INVALID_CONNECTION_ID;
    int cNetworks = 0;
    int iNetwork = 0; 
    int ret=SUCCESS;
    
     Serial.println("Begin WiFiCmdRobot Init");
 
  
    // initialize the SD-Card    
    ret = initSDCard();
    if (ret != SUCCESS)
    {  
        Serial.print("Error Init SD-Card, error: ");
        Serial.println(ret);
    }                                                                    
    else
    {
        Serial.println("Init SD-Card OK");
        Serial.println("");
    }
    
    // get infos from SD-Card  
    ret=infoSDCard();
    if (ret != SUCCESS)
    {  
        Serial.print("Error Infos SD-Card, error: ");
        Serial.println(ret);
    }
    
    Serial.println("Begin WIFI Init"); 
    lcd.clear();
    lcd.print("Begin WIFI Init");
           
    // set my default wait time to nothing
    DNETcK::setDefaultBlockTime(DNETcK::msImmediate); 

    // start a scan
    DWIFIcK::beginScan();
    while (1)
    {
            // every pass through loop(), keep the stack alive
            DNETcK::periodicTasks(); 
            if(DWIFIcK::isScanDone(&cNetworks, &status))
            {
                Serial.println("Scan Done");
                break;
            }
            else if(DNETcK::isStatusAnError(status))
            {
                Serial.print("Scan Failed");
                return -1;
            }
            
    }        
    
    while (1)
    {            
            // every pass through loop(), keep the stack alive
            DNETcK::periodicTasks();            
            if(iNetwork < cNetworks)
            {
                DWIFIcK::SCANINFO scanInfo;
                int j = 0;

                if(DWIFIcK::getScanInfo(iNetwork, &scanInfo))
                {
                    Serial.print("Scan info for index: ");
                    Serial.println(iNetwork, DEC);

                    Serial.print("SSID: ");
                    Serial.println(scanInfo.szSsid);

                    Serial.print("Secuity type: ");
                    Serial.println(scanInfo.securityType, DEC);
                    switch(scanInfo.securityType)
                    {
                           case DWIFIcK::WF_SECURITY_OPEN:
                                Serial.println("SECURITY OPEN");
                                break;
                           case DWIFIcK::WF_SECURITY_WEP_40:
                                Serial.println("WF SECURITY WEP 40");
                                break;
                           case DWIFIcK::WF_SECURITY_WEP_104:
                                Serial.println("SECURITY WEP 104");
                                break;
                           case DWIFIcK::WF_SECURITY_WPA_WITH_KEY:
                                Serial.println("SECURITY WPA WITH KEY");
                                break;
                           case DWIFIcK::WF_SECURITY_WPA_WITH_PASS_PHRASE:
                                Serial.println("SECURITY WPA WITH PASS PHRASE");
                                break;
                           case DWIFIcK::WF_SECURITY_WPA2_WITH_KEY:
                                Serial.println("SECURITY WPA2 WITH KEY");
                                break;
                           case DWIFIcK::WF_SECURITY_WPA2_WITH_PASS_PHRASE:
                                Serial.println("SECURITY WPA2 WITH PASS PHRASE");
                                break;
                           case DWIFIcK::WF_SECURITY_WPA_AUTO_WITH_KEY:
                                Serial.println("SECURITY WPA AUTO WITH KEY");
                                break; 
                           case DWIFIcK::WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE:
                                Serial.println("SECURITY WPA AUTO WITH PASS PHRASE");
                                break;                                
                    }
                    
                    Serial.print("Channel: ");
                    Serial.println(scanInfo.channel, DEC);    

                    Serial.print("Signal Strength: ");
                    Serial.println(scanInfo.signalStrength, DEC);    

                    Serial.print("Count of supported bit rates: ");
                    Serial.println(scanInfo.cBasicRates, DEC);    

                    for( j= 0; j< scanInfo.cBasicRates; j++)
                    {
                        Serial.print("\tSupported Rate: ");
                        Serial.print(scanInfo.basicRates[j], DEC); 
                        Serial.println(" bps");
                    }

                    Serial.print("SSID MAC: ");
                    for(j=0; j<sizeof(scanInfo.ssidMAC); j++)
                    {
                        if(scanInfo.ssidMAC[j] < 16)
                        {
                            Serial.print(0, HEX);
                        }
                        Serial.print(scanInfo.ssidMAC[j], HEX);
                    }

                    Serial.print("\nBeacon Period: ");
                    Serial.println(scanInfo.beconPeriod, DEC);    

                    Serial.print("dtimPeriod: ");
                    Serial.println(scanInfo.dtimPeriod, DEC);    

                    Serial.print("atimWindow: ");
                    Serial.println(scanInfo.atimWindow, DEC); 
                    
                    Serial.println("");
                }
                else
                {
                    Serial.print("Unable to get scan info for iNetwork: ");
                    Serial.println(iNetwork, DEC);
                }

                iNetwork++;
            }
            else
            {
                break;
            }           
    }

    if((conID = WiFiConnectMacro()) != DWIFIcK::INVALID_CONNECTION_ID)
    {
          Serial.print("Connection Created, ConID = ");
          Serial.println(conID, DEC);
    }
    else
    {
          Serial.print("Unable to connection, status: ");
          Serial.println(status, DEC);
          return -2;
    }
 
    while (1)
    { 
           // every pass through loop(), keep the stack alive
           DNETcK::periodicTasks(); 
            
          // initialize the stack with a static IP
          DNETcK::begin(ipServer);
          if(DNETcK::isInitialized(&status))
          {
                Serial.println("IP Stack Initialized");
                break;
          }
          else if(DNETcK::isStatusAnError(status))
          {
                Serial.print("Error in initializing, status: ");
                Serial.println(status, DEC);
                return -3;
          }
    }
        
    Serial.println("");
    IPv4 ip;

    DNETcK::getMyIP(&ip);
    Serial.print("My ");
    printIP(ip);
    Serial.println("");

    DNETcK::getGateway(&ip);
    Serial.print("Gateway ");
    printIP(ip);
    Serial.println("");

    DNETcK::getSubnetMask(&ip);
    Serial.print("Subnet mask: ");
    printNumb(ip.rgbIP, 4, '.');
    Serial.println("");

    DNETcK::getDns1(&ip);
    Serial.print("Dns1 ");
    printIP(ip);
    Serial.println("");

    DNETcK::getDns2(&ip);
    Serial.print("Dns2 ");
    printIP(ip);
    Serial.println("");
       
    
    DWIFIcK::CONFIGINFO configInfo;
    if(DWIFIcK::getConfigInfo(&configInfo))
    {
        Serial.println("WiFi config information");

        Serial.print("Scan Type: ");
        switch(configInfo.scanType)
        {
                   case DWIFIcK::WF_ACTIVE_SCAN:
                        Serial.println("ACTIVE SCAN");
                        break;
                   case DWIFIcK::WF_PASSIVE_SCAN:
                        Serial.println("PASSIVE SCAN");
                        break;                
        }

        Serial.print("Beacon Timeout: ");
        Serial.println(configInfo.beaconTimeout, DEC);

        Serial.print("Connect Retry Count: ");
        Serial.println(configInfo.connectRetryCount, DEC);

        Serial.print("Scan Count: ");
        Serial.println(configInfo.scanCount, DEC);

        Serial.print("Minimum Signal Strength: ");
        Serial.println(configInfo.minSignalStrength, DEC);

        Serial.print("Minimum Channel Time: ");
        Serial.println(configInfo.minChannelTime, DEC);

        Serial.print("Maximum Channel Time: ");
        Serial.println(configInfo.maxChannelTime, DEC);

        Serial.print("Probe Delay: ");
        Serial.println(configInfo.probeDelay, DEC);

        Serial.print("Polling Interval: ");
        Serial.println(configInfo.pollingInterval, DEC);                                                 
    }
    else
    {
        Serial.println("Unable to get WiFi config data");
        return -4; 
    }                  
   
    tcpServer.startListening(portServer);

    lcd.setCursor(0,1); 
    lcd.print("End   WIFI Init");
    
    Serial.println("");
    Serial.println("End WiFiCmdRobot Init");
    Serial.println("*********************");
    Serial.println("");

    return SUCCESS;                        
}
Ejemplo n.º 2
0
int robot_begin()
{
  int ret = SUCCESS;
  int ivalue = 0;
  
  ret = motor_begin(); 
  if (ret != SUCCESS) return ret;

  Serial.println("Begin Robot Init");
  Serial.println("****************");
  
  lcd.clear();
  lcd.print("Begin Robot Init");
   
  pinMode(Led_Green, OUTPUT);      // set the pin as output
  blink(Led_Green); 
  pinMode(Led_Red, OUTPUT);      // set the pin as output
  blink(Led_Red);  
  pinMode(Led_Blue, OUTPUT);     // set the pin as output
  blink(Led_Blue);
  Serial.println("Init Leds OK");
    
  // initialize the buzzer
  pinMode(buzzPin, OUTPUT); 
  buzz(3);       
  Serial.println("Init Buzzer OK");
   
  // initialize the Tilt&Pan servos  
  TiltPan_begin(HSERVO_Pin, VSERVO_Pin);
  Serial.println("Init Tilt&Pan servos OK");

  // initialize the camera
  Serial.println(" ");
  Serial.println("Begin Init Camera...");
  ret=JPEGCamera.begin();
  if (ret != SUCCESS)
  {  
        Serial.print("Error Init Camera, error: ");
        Serial.println(ret);
        lcd.setCursor(0,1); 
        lcd.print("Init Camera KO  ");
  }        
  else
  {
        Serial.println("Init Camera OK");
        lcd.setCursor(0,1); 
        lcd.print("Init Camera OK  ");
  } 
  delay(5*1000);lcd.clear();    
  
  // initialize the SD-Card    
  ret = initSDCard();
  if (ret != SUCCESS)
  {  
        Serial.print("Error Init SD-Card, error: ");
        Serial.println(ret);
        lcd.print("Init SD-Card KO ");
  }                                                                    
  else
  {
        Serial.println("Init SD-Card OK");
        lcd.print("Init SD-Card OK ");
  }
    
  // get infos from SD-Card  
  ret=infoSDCard();
  if (ret < 0)
  {  
        Serial.print("Error Infos SD-Card, error: ");
        Serial.println(ret);
        lcd.setCursor(0,1); 
        lcd.print("Err Infos SDCard");
  }
  else
  {
        no_picture = ret+1;
        Serial.print("no_picture starts at: ");
        Serial.println(no_picture);
        lcd.setCursor(0,1); 
        lcd.print("Num picture:");lcd.print(no_picture);
  }   
  delay(5*1000);lcd.clear();  
    
    
  // initialize the brightness sensor   
  TEMT6000.TEMT6000_init(TEMT6000_Pin); // initialize the pin connected to the sensor
  Serial.println("Init Brightness sensor OK");
  
  ivalue = TEMT6000.TEMT6000_getLight();
  Serial.print("Value between 0 (dark) and 1023 (bright): ");
  Serial.println(ivalue); 
  lcd.print("Lux:");lcd.print(ivalue);lcd.printByte(lcd_pipe);
  
  // initialize the temperature sensor   
  TMP102.TMP102_init();
  Serial.println("Init Temperature sensor OK");
  
  double temperature = TMP102.TMP102_read();
  ivalue = (int)(100.0 * temperature);
  Serial.print("Temperature: ");
  Serial.println(ivalue); 
  lcd.print("T:");lcd.print(ivalue);lcd.printByte(lcd_celcius);lcd.printByte(lcd_pipe);   
  
  // initialize the electret micro   
  //Micro.Micro_init(MICRO_Pin); // initialize the pin connected to the micro
  //Serial.println("Init Micro OK");

  // initialize the motion sensor
  pinMode(MOTION_PIN, INPUT);
  Serial.println("Init Motion sensor OK");

  // initialize the IOT Serial 1 
  IOTSerial.IOTSbegin(1); // initialize the IOT Serial 1 to communicate with IOT WIFClient ESP8266
  Serial.println ("Init IOT Serial 1 to communicate with IOT WIFClient ESP8266 OK");
  
  // initialize the IOT Serial 2, interrupt setting
  IOTSerial.IOTSbegin(2); // initialize the IOT Serial 2 to communicate with IOT WIFServer ESP8266
  Serial.println ("Init IOT Serial 2 to communicate with IOT WIFServer ESP8266 OK");
  pinMode(IOT_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(IOT_PIN), IntrIOT, RISING);         // set IOT interrupt
 
  interrupts(); // enable all interrupts
  Serial.print("Init Interrupts OK, IntIOT: "); Serial.println(IntIOT);
  
  lcd.setCursor(0,1); 
  lcd.print("End   Robot Init");
  delay(5*1000);lcd.clear();  
 
  Serial.println("End Robot Init");
  Serial.println("**************");
  Serial.println("");
 
  return SUCCESS;
  
}