예제 #1
0
void wifi_connect() {
  char response[256];
  char response_len;

  printf_P(PSTR("[WIFI] Connecting...\n"));

  wifi_enable();
  _delay_ms(50);

  // Reset wireless
  fputs_P(AT_RST, serial_output);
  _delay_ms(50);
  while(serial_available()) fgetc(serial_input);

  wifi_repeat_until_ok("AT\r\n");

  fputs_P(AT_CWMODE_1, serial_output);
  _delay_ms(50);
  print_response();

  fprintf_P(serial_output, AT_CWJAP, WIFI_SSID, WIFI_PASS);
  print_response();

  // TODO: Retry connect after x failures
  while(!wifi_is_connected());

  fputs_P(AT_CIPMUX_0, serial_output);
  print_response();

  printf_P(PSTR("[WIFI] Connected.\n"));
}
예제 #2
0
static void cmd_wifi(Stream *chp, int argc, char* argv[])
{
   if (argc < 1) {
      chprintf(chp, "Usage: wifi on|off|info|ap|shell\r\n");
      return;
   } 
   if (strncasecmp("info", argv[0], 3) == 0) {
      if (wifi_is_enabled()) {
        chprintf(chp, "    Stn status: %s\r\n",  wifi_status(buf));
        chprintf(chp, "  Connected to: %s\r\n",  wifi_doCommand("CONF", buf));
        chprintf(chp, "    IP address: %s\r\n",  wifi_doCommand("IP", buf));
        chprintf(chp, "   MAC address: %s\r\n",  wifi_doCommand("MAC", buf));
      
        chprintf(chp, "\r\n");
        chprintf(chp, "       AP SSID: %s\r\n",  wifi_doCommand("AP.SSID", buf));     
        chprintf(chp, " AP IP address: %s\r\n",  wifi_doCommand("AP.IP", buf));
      }
      else
        chprintf(chp, " WIFI is off\r\n");

      chprintf(chp, "\r\nConfigured access points:\r\n");
      for (int i=0; i<N_WIFIAP; i++) {
         GET_PARAM_I(WIFIAP, i, &wifiap);
         if (strlen(wifiap.ssid) == 0)
            chprintf(chp, " %d: -\r\n", i+1);
         else
            chprintf(chp," %d: %s : '%s'\r\n", i+1, wifiap.ssid, wifiap.passwd);
      }
   }
   else if (strncasecmp("ap", argv[0], 2) == 0) {
      if (argc < 2)
         chprintf(chp, "Usage: wifi ap <1-%d>\r\n", N_WIFIAP);
      else {
         int i = atoi(argv[1]);
         if (i < 1 || i > 4) {
            chprintf(chp, "Argument must be a number 1-4\r\n");
            return; 
         }
         chprintf(chp, "Enter SSID: ");
         shellGetLine(chp, wifiap.ssid, 32);
         if (strlen(wifiap.ssid) > 0) {
            chprintf(chp, "Enter Password: "******"_OPEN_");
         chprintf(chp, "Ok\r\n");
         SET_PARAM_I(WIFIAP, i-1, &wifiap);
      }
   }
   else if (strncasecmp("shell", argv[0], 2) == 0) {
     chprintf(chp, "***** WIFI DEVICE SHELL. Ctrl-D to exit *****\r\n");
     wifi_shell(chp);
   }
   else if (strncasecmp("on", argv[0], 2) == 0) { 
     wifi_enable();
     chprintf(chp, "***** WIFI MODULE ON *****\r\n");
   }
   else if (strncasecmp("off", argv[0], 2) == 0) {
     chprintf(chp, "***** WIFI MODULE OFF *****\r\n");
     wifi_disable();
   }
}