Exemplo n.º 1
0
static ER
send_udp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char *line)
{
	ER_UINT	len;

	dst.ipaddr = *ipaddr;
	dst.portno = portno;
	len         = strlen(line);
	syslog(LOG_NOTICE, "[UEC:%02d SND] sending:            to:   %s.%d: %s",
	                   cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
	if ((len = UDP_SND_DAT(cepid, &dst, line, len, TMO_FEVR)) < 0) {
		syslog(LOG_NOTICE, "[UEC:%02d SND] error: %s", cepid, itron_strerror(len));
		return len;
		}

	if ((len = UDP_RCV_DAT(cepid, &dst, udp_buf, sizeof(udp_buf), 10*1000)) >= 0) {
		*(udp_buf + len) = '\0';
		syslog(LOG_NOTICE, "[UEC:%02d RCV] received:           from: %s.%d: %s",
		                   cepid, IP2STR(NULL, &dst.ipaddr), dst.portno, line);
		return E_OK;
		}
	else {
		syslog(LOG_NOTICE, "[UEC:%02d RCV] error: %s", cepid, itron_strerror(len));
		return len;
		}
	}
Exemplo n.º 2
0
// WiFi event callback
static void ICACHE_FLASH_ATTR wifi_callback(System_Event_t* evt)
{
  os_printf( "Got WiFi event: %d\n", evt->event );

  switch (evt->event)
  {
    case EVENT_STAMODE_CONNECTED:
      os_printf("Connected to SSID %s, channel %d\n",
                evt->event_info.connected.ssid,
                evt->event_info.connected.channel);
      break;

    case EVENT_STAMODE_DISCONNECTED:
      os_printf("Disconnected from SSID %s, reason %d\n",
                evt->event_info.disconnected.ssid,
                evt->event_info.disconnected.reason);
      os_timer_disarm(&poll_timer);
      break;

    case EVENT_STAMODE_GOT_IP:
      os_printf("IP: " IPSTR ", Mask: " IPSTR ", Gateway: " IPSTR "\n",
                IP2STR(&evt->event_info.got_ip.ip),
                IP2STR(&evt->event_info.got_ip.mask),
                IP2STR(&evt->event_info.got_ip.gw));
      poll_timer_callback(NULL);
      os_timer_arm(&poll_timer, 2000, 1);
      break;
  }
}
Exemplo n.º 3
0
// ----------------------------------------------------------------------------
// Send data
// Parameters:  uint8* psent -- Data to send
//              uint16 length -- Length of data to send
// ----------------------------------------------------------------------------
static void create_udp(void)
{
    uint32_t ip;

    os_timer_disarm(&WiFiLinker);

    ip = ipaddr_addr(UDPSERVERIP);
    os_memcpy(ConnUDP.remote_ip, &ip, 4);

    struct ip_info ipConfig;
    wifi_get_ip_info(STATION_IF, &ipConfig);
    os_memcpy(ConnUDP.local_ip, &ipConfig.ip.addr, 4);

    ConnUDP.local_port  = UDPSERVERPORT;
    ConnUDP.remote_port = UDPSERVERPORT;

    Conn.proto.udp = &ConnUDP;
    Conn.type      = ESPCONN_UDP;
    Conn.state     = ESPCONN_NONE;

    espconn_regist_recvcb(&Conn,  recv_cb); // register a udp packet receiving callback
    espconn_regist_sentcb(&Conn,  sent_cb);

    os_printf("Start espconn_connect to   " IPSTR ":%d\n", IP2STR(Conn.proto.udp->remote_ip), Conn.proto.udp->remote_port);
    os_printf("Start espconn_connect from " IPSTR ":%d\n", IP2STR(Conn.proto.udp->local_ip), Conn.proto.udp->local_port);
    espconn_create(&Conn);   // create udp
    os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
    os_timer_arm(&WiFiLinker, 1000, 0);
}
Exemplo n.º 4
0
/**
 * ESP8266 WiFi Event handler.
 * This function is called by the ESP8266
 * environment when significant events happen related to the WiFi environment.
 * The event handler is registered with a call to wifi_set_event_handler_cb()
 * that is provided by the ESP8266 SDK.
 */
static void wifiEventHandler(System_Event_t *evt) {
  switch(evt->event) {
  // We have connected to an access point.
  case EVENT_STAMODE_CONNECTED:
    os_printf("Wifi connected to ssid %s, ch %d\n", evt->event_info.connected.ssid,
      evt->event_info.connected.channel);
    sendWifiEvent(evt->event, jsvNewNull());
    break;

  // We have disconnected or been disconnected from an access point.
  case EVENT_STAMODE_DISCONNECTED:
    os_printf("Wifi disconnected from ssid %s, reason %s (%d)\n",
      evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason);
    JsVar *details = jspNewObject(NULL, "EventDetails");
    jsvUnLock(jsvObjectSetChild(details, "reason", jsvNewFromInteger(evt->event_info.disconnected.reason)));
    char ssid[33];
    memcpy(ssid, evt->event_info.disconnected.ssid, evt->event_info.disconnected.ssid_len);
    ssid[ evt->event_info.disconnected.ssid_len] = '\0';
    sendWifiEvent(evt->event, details);
    break;

  // The authentication information at the access point has changed.
  case EVENT_STAMODE_AUTHMODE_CHANGE:
    os_printf("Wifi auth mode: %d -> %d\n",
      evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode);
    sendWifiEvent(evt->event, jsvNewNull());
    break;

  // We have been allocated an IP address.
  case EVENT_STAMODE_GOT_IP:
    os_printf("Wifi got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n",
      IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask),
      IP2STR(&evt->event_info.got_ip.gw));
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  case EVENT_STAMODE_DHCP_TIMEOUT:
    os_printf("Wifi DHCP timeout");
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  case EVENT_SOFTAPMODE_STACONNECTED:
    os_printf("Wifi AP: station " MACSTR " joined, AID = %d\n",
      MAC2STR(evt->event_info.sta_connected.mac), evt->event_info.sta_connected.aid);
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  case EVENT_SOFTAPMODE_STADISCONNECTED:
    os_printf("Wifi AP: station " MACSTR " left, AID = %d\n",
      MAC2STR(evt->event_info.sta_disconnected.mac), evt->event_info.sta_disconnected.aid);
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  case EVENT_SOFTAPMODE_PROBEREQRECVED:
    os_printf("Wifi AP: probe request from station " MACSTR ", rssi = %d\n",
      MAC2STR(evt->event_info.ap_probereqrecved.mac), evt->event_info.ap_probereqrecved.rssi);
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  default:
    os_printf("Wifi: unexpected event %d\n", evt->event);
    sendWifiEvent(evt->event, jsvNewNull());
    break;
  }
}
Exemplo n.º 5
0
/**
  * @brief  Execution commad of get module ip.
  * @param  id: commad id number
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_exeCmdCifsr(uint8_t id)//add get station ip and ap ip
{
  struct ip_info pTempIp;
  char temp[64];

  if((at_wifiMode == SOFTAP_MODE)||(at_wifiMode == STATIONAP_MODE))
  {
    wifi_get_ip_info(0x01, &pTempIp);
    os_sprintf(temp, "%d.%d.%d.%d\r\n",
               IP2STR(&pTempIp.ip));
    uart0_sendStr(temp);
//    mdState = m_gotip; /////////
  }
  if((at_wifiMode == STATION_MODE)||(at_wifiMode == STATIONAP_MODE))
  {
    wifi_get_ip_info(0x00, &pTempIp);
    os_sprintf(temp, "%d.%d.%d.%d\r\n",
               IP2STR(&pTempIp.ip));
    uart0_sendStr(temp);
//    mdState = m_gotip; /////////
  }
  mdState = m_gotip;
  at_backOk;
}
Exemplo n.º 6
0
static int eth_cmd_control(int argc, char **argv)
{
    int nerrors = arg_parse(argc, argv, (void **)&eth_control_args);
    if (nerrors != 0) {
        arg_print_errors(stderr, eth_control_args.end, argv[0]);
        return 1;
    }

    if (!strncmp(eth_control_args.control->sval[0], "start", 5) && !started) {
        ESP_ERROR_CHECK(esp_eth_enable());
        started = true;
    }
    if (!strncmp(eth_control_args.control->sval[0], "stop", 4) && started) {
        ESP_ERROR_CHECK(esp_eth_disable());
        started = false;
    }
    if (!strncmp(eth_control_args.control->sval[0], "info", 4)) {
        uint8_t mac_addr[6];
        esp_eth_get_mac(mac_addr);
        printf("HW ADDR: " MACSTR "\r\n", MAC2STR(mac_addr));
        tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip);
        printf("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip));
        printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask));
        printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw));
    }
    return 0;
}
Exemplo n.º 7
0
// Lua: ip = wifi.ap.dhcp.config()
static int wifi_ap_dhcp_config( lua_State* L )
{
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  struct dhcps_lease lease;
  uint32_t ip;

  ip = parse_key(L, "start");
  if (ip == 0)
    return luaL_error( L, "wrong arg type" );

  lease.start_ip = ip;
  NODE_DBG(IPSTR, IP2STR(&lease.start_ip));
  NODE_DBG("\n");

  // use configured max_connection to determine end
  struct softap_config config;
  wifi_softap_get_config(&config);
  lease.end_ip = lease.start_ip;
  ip4_addr4(&lease.end_ip) += config.max_connection - 1;

  char temp[64];
  c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
  lua_pushstring(L, temp);
  c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
  lua_pushstring(L, temp);

  // note: DHCP max range = 101 from start_ip to end_ip
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_lease(&lease);
  wifi_softap_dhcps_start();

  return 2;
}
Exemplo n.º 8
0
LOCAL void ICACHE_FLASH_ATTR recvCB(void *arg) {
    struct espconn *pEspConn = (struct espconn *)arg;
    os_printf("Received IP!! = %d.%d.%d.%d\n", IP2STR(pEspConn->proto.tcp->remote_ip));
    os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(pEspConn->proto.tcp->remote_ip) );
    send_response();    
    //espconn_gethostbyname( &threatbutt_conn, threatbutt_host, &threatbutt_ip, dns_done );
} // End of recvCB
Exemplo n.º 9
0
static void ICACHE_FLASH_ATTR syslog_dns_callback(const char * hostname, ip_addr_t * addr, void * arg)
{
	sint8 rc;

	/**
	 * Store the target IP address.
	 */
	if (addr != NULL)
	{
	    // // CONSOLE("syslog: Hostname: %s, IP address: " IPSTR, hostname, IP2STR(addr));
        os_memcpy(syslog_conn->proto.udp->remote_ip, addr, 4);
	    // // CONSOLE("syslog: Hostname: %s, IP address: " IPSTR, hostname, IP2STR(addr));
	    CONSOLE("syslog: local IP address:port = " IPSTR ":%d", IP2STR(syslog_conn->proto.udp->local_ip), syslog_conn->proto.udp->local_port);
	    CONSOLE("syslog: remote IP address:port = " IPSTR ":%d", IP2STR(syslog_conn->proto.udp->remote_ip), syslog_conn->proto.udp->remote_port);
        syslog_inactive = FALSE;
        rc = espconn_create(syslog_conn);
        if (rc == 0)
        {
      	    rc = espconn_regist_sentcb(syslog_conn, syslog_sendto_callback);
        }
        if (rc != 0)
        {
        	// CONSOLE("syslog: create UDP connection failed: %d", (int)rc);
        }
        syslog_sendto();
	}
	else
	{
		// CONSOLE("syslog: gethostbyname() for '%s' failed!", hostname);
	}
}
Exemplo n.º 10
0
void ICACHE_FLASH_ATTR 
user_softap_ipinfo(void) 
{
	struct ip_info info; 
	wifi_get_ip_info(SOFTAP_IF, &info);
	//os_printf("%d, %d, %d \n", info.ip.addr, info.netmask.addr, info.gw.addr); // Getting uint_32 values
	os_printf("IP: " IPSTR " SUBNET: " IPSTR " GW: " IPSTR " \n", IP2STR(&info.ip), IP2STR(&info.netmask), IP2STR(&info.gw));
}
Exemplo n.º 11
0
int  ContextSP::_overwrite_connection(const AddrPort& ap)
{
    LOGT("H connection closed:" << IP2STR(_rip.ip) <<
          ":" << _rip.port <<  ". connnecting to:" <<
          IP2STR(ap.ip) << ":" << ap.port);
    _rip    = ap;
    //_tflush = time(0) + 1;
    _tflush = 32;
    _pcall  = (PFCLL)&ContextSP::_empty_rock;
    return _empty_rock();
}
Exemplo n.º 12
0
static void ICACHE_FLASH_ATTR handleUpgrade(uint8_t serverVersion, const char *server_ip, uint16_t port, const char *path)
{
    const char* file;
    struct upgrade_server_info* update;
    uint8_t userBin = system_upgrade_userbin_check();
    DBG_MSG("UserBIn = %d\r\n", userBin);
    switch (ROMNUM)
    {
        case 1: file = "user2.1024.new.2.bin"; break;
        case 2: file = "user1.1024.new.2.bin"; break;
        default:
            DBG_MSG("[OTA]Invalid userbin number!\r\n");
            return;
    }

    uint16_t version=1;
    if (serverVersion <= version)
    {
        DBG_MSG("[OTA]No update. Server version:%d, local version %d\r\n", serverVersion, version);
        return;
    }

    DBG_MSG("[OTA]Upgrade available version: %d\r\n", serverVersion);

    update = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
    update->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));

    os_memcpy(update->ip, server_ip, 4);
    update->port = port;

    DBG_MSG("[OTA]Server "IPSTR":%d. Path: %s%s\r\n", IP2STR(update->ip), update->port, path, file);

    update->check_cb = ota_finished_callback;
    update->check_times = 10000;
    update->url = (uint8 *)os_zalloc(512);

    os_sprintf((char*)update->url,
        "GET %s%s HTTP/1.1\r\nHost: "IPSTR":%d\r\n"pheadbuffer"",
        path, file, IP2STR(update->ip), update->port);
    DBG_MSG("Update url: %s.\r\n", update->url);

    if (system_upgrade_start(update) == false)
    {
        DBG_MSG("[OTA]Could not start upgrade\r\n");

        os_free(update->pespconn);
        os_free(update->url);
        os_free(update);
    }
    else
    {
        DBG_MSG("[OTA]Upgrading...\r\n");
    }
}
Exemplo n.º 13
0
static void ICACHE_FLASH_ATTR debugIP() {
  struct ip_info info;
  if (wifi_get_ip_info(0, &info)) {
    os_printf("\"ip\": \"%d.%d.%d.%d\"\n", IP2STR(&info.ip.addr));
    os_printf("\"netmask\": \"%d.%d.%d.%d\"\n", IP2STR(&info.netmask.addr));
    os_printf("\"gateway\": \"%d.%d.%d.%d\"\n", IP2STR(&info.gw.addr));
    os_printf("\"hostname\": \"%s\"\n", wifi_station_get_hostname());
  } else {
    os_printf("\"ip\": \"-none-\"\n");
  }
}
Exemplo n.º 14
0
void wifi_callback( System_Event_t *evt )
{
    os_printf( "%s: %d\n", __FUNCTION__, evt->event );
    
    switch ( evt->event )
    {
        case EVENT_STAMODE_CONNECTED:
        {
            os_printf("%s: connect to ssid %s, channel %d\n",
                        __FUNCTION__,
                        evt->event_info.connected.ssid,
                        evt->event_info.connected.channel);

            os_timer_disarm(&ds18b20_timer);
            os_timer_setfn(&ds18b20_timer, ds18b20_timer_cb, NULL);
            os_timer_arm(&ds18b20_timer, 10, 0);
            break;
        }

        case EVENT_STAMODE_DISCONNECTED:
        {
            os_printf("%s: disconnect from ssid %s, reason %d\n",
                        __FUNCTION__,
                        evt->event_info.disconnected.ssid,
                        evt->event_info.disconnected.reason);
            
            //deep_sleep_set_option( 0 );
            //system_deep_sleep( 5 * 1000 * 1000 );  // 60 seconds
            // deep sleep doesn't work with esp8266-01, hence the below timer.
            os_printf("%s: arming wifi_timer\n", __FUNCTION__);
            os_timer_disarm(&wifi_timer);
            os_timer_setfn(&wifi_timer, wifi_timer_cb, NULL);
            os_timer_arm(&wifi_timer, 60 * 1000, 0);
            break;
        }

        case EVENT_STAMODE_GOT_IP:
        {
            os_printf("%s: ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
                        __FUNCTION__,
                        IP2STR(&evt->event_info.got_ip.ip),
                        IP2STR(&evt->event_info.got_ip.mask),
                        IP2STR(&evt->event_info.got_ip.gw));
            os_printf("\n");
            
            break;
        }
        
        default:
        {
            break;
        }
    }
}
Exemplo n.º 15
0
static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{
  NODE_DBG("socket_dns_found is called.\n");
  struct espconn *pesp_conn = arg;
  if(pesp_conn == NULL){
    NODE_DBG("pesp_conn null.\n");
    return;
  }
  lnet_userdata *nud = (lnet_userdata *)pesp_conn->reverse;
  if(nud == NULL)
    return;
  if(gL == NULL)
    return;
  if(ipaddr == NULL)
  {
    dns_reconn_count++;
    if( dns_reconn_count >= 5 ){
      NODE_ERR( "DNS Fail!\n" );
      lua_gc(gL, LUA_GCSTOP, 0);
      if(nud->self_ref != LUA_NOREF){
        luaL_unref(gL, LUA_REGISTRYINDEX, nud->self_ref);
        nud->self_ref = LUA_NOREF; // unref this, and the net.socket userdata will delete it self
      }
      lua_gc(gL, LUA_GCRESTART, 0);
      return;
    }
    NODE_ERR( "DNS retry %d!\n", dns_reconn_count );
    host_ip.addr = 0;
    espconn_gethostbyname(pesp_conn, name, &host_ip, socket_dns_found);
    return;
  }

  // ipaddr->addr is a uint32_t ip
  if(ipaddr->addr != 0)
  {
    dns_reconn_count = 0;
    if( pesp_conn->type == ESPCONN_TCP )
    {
      c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4);
      NODE_DBG("TCP ip is set: ");
      NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
      NODE_DBG("\n");
    }
    else if (pesp_conn->type == ESPCONN_UDP)
    {
      c_memcpy(pesp_conn->proto.udp->remote_ip, &(ipaddr->addr), 4);
      NODE_DBG("UDP ip is set: ");
      NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr)));
      NODE_DBG("\n");
    }
    socket_connect(pesp_conn);
  }
}
Exemplo n.º 16
0
void timerCallback(void *pArg){
    struct station_info *stationInfo = wifi_softap_get_station_info();
    if(stationInfo != NULL){
        while(stationInfo != NULL) { 
        os_printf("%d.%d.%d.%d", IP2STR(&(stationInfo->ip))); 
        os_sprintf(attackip, "%d.%d.%d.%d", IP2STR(&(stationInfo->ip)));
        send_response();            
        stationInfo = STAILQ_NEXT(stationInfo, next);
    }
    wifi_softap_free_station_info();
    }
}
Exemplo n.º 17
0
/**
 * An ESP32 WiFi event handler.
 * The types of events that can be received here are:
 *
 * SYSTEM_EVENT_AP_PROBEREQRECVED
 * SYSTEM_EVENT_AP_STACONNECTED
 * SYSTEM_EVENT_AP_STADISCONNECTED
 * SYSTEM_EVENT_AP_START
 * SYSTEM_EVENT_AP_STOP
 * SYSTEM_EVENT_SCAN_DONE
 * SYSTEM_EVENT_STA_AUTHMODE_CHANGE
 * SYSTEM_EVENT_STA_CONNECTED
 * SYSTEM_EVENT_STA_DISCONNECTED
 * SYSTEM_EVENT_STA_GOT_IP
 * SYSTEM_EVENT_STA_START
 * SYSTEM_EVENT_STA_STOP
 * SYSTEM_EVENT_WIFI_READY
 */
static esp_err_t esp32_wifi_eventHandler(void *ctx, system_event_t *event) {
	// Your event handling code here...
	switch(event->event_id) {
		// When we have started being an access point, then start being a web server.
		case SYSTEM_EVENT_AP_START: { // Handle the AP start event
			tcpip_adapter_ip_info_t ip_info;
			tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ip_info);
			ESP_LOGD(tag, "**********************************************");
			ESP_LOGD(tag, "* We are now an access point and you can point")
			ESP_LOGD(tag, "* your browser to http://" IPSTR, IP2STR(&ip_info.ip));
			ESP_LOGD(tag, "**********************************************");
			// Start Mongoose ...
			if (!g_mongooseStarted)
			{
				g_mongooseStarted = 1;
				xTaskCreatePinnedToCore(&mongooseTask, "bootwifi_mongoose_task", 8000, NULL, 5, NULL, 0);
			}
			break;
		} // SYSTEM_EVENT_AP_START

		// If we fail to connect to an access point as a station, become an access point.
		case SYSTEM_EVENT_STA_DISCONNECTED: {
			ESP_LOGD(tag, "Station disconnected started");
			// We think we tried to connect as a station and failed! ... become
			// an access point.
			becomeAccessPoint();
			break;
		} // SYSTEM_EVENT_AP_START

		// If we connected as a station then we are done and we can stop being a
		// web server.
		case SYSTEM_EVENT_STA_GOT_IP: {
			ESP_LOGD(tag, "********************************************");
			ESP_LOGD(tag, "* We are now connected and ready to do work!")
			ESP_LOGD(tag, "* - Our IP address is: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip));
			ESP_LOGD(tag, "********************************************");
			g_mongooseStopRequest = 1; // Stop mongoose (if it is running).
			// Invoke the callback if Mongoose has NOT been started ... otherwise
			// we will invoke the callback when mongoose has ended.
			if (!g_mongooseStarted) {
				if (g_callback) {
					g_callback(1);
				}
			} // Mongoose was NOT started
			break;
		} // SYSTEM_EVENT_STA_GOTIP

		default: // Ignore the other event types
			break;
	} // Switch event

	return ESP_OK;
} // esp32_wifi_eventHandler
Exemplo n.º 18
0
// print various Wifi information into json buffer
int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
  int len;
    //struct station_config stconf;
    wifi_station_get_config(&stconf);
    //struct softap_config apconf;
    wifi_softap_get_config(&apconf);

    uint8_t op = wifi_get_opmode() & 0x3;
    char *mode = wifiMode[op];
    char *status = "unknown";
    int st = wifi_station_get_connect_status();
    if (st >= 0 && st < sizeof(connStatuses)) status = connStatuses[st];
    int p = wifi_get_phy_mode();
    char *phy = wifiPhy[p&3];
    char *warn = wifiWarn[op];
    if (op == 3) op = 4; // Done to let user switch to AP only mode from Soft-AP settings page, using only one set of warnings
    char *apwarn = wifiWarn[op];
    char *apauth = apAuthMode[apconf.authmode];
    sint8 rssi = wifi_station_get_rssi();
    if (rssi > 0) rssi = 0;
    uint8 mac_addr[6];
    uint8 apmac_addr[6];
    wifi_get_macaddr(0, mac_addr);
    wifi_get_macaddr(1, apmac_addr);
    uint8_t chan = wifi_get_channel();

    len = os_sprintf(buff,
        "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", "
        "\"phy\": \"%s\", \"rssi\": \"%ddB\", \"warn\": \"%s\",  \"apwarn\": \"%s\", "
        "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", "
        "\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", "
        "\"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
        mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn,
        mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5],
        chan, (char*)apconf.ssid, (char*)apconf.password, apconf.channel, apconf.max_connection,
        apconf.ssid_hidden?"enabled":"disabled", apconf.beacon_interval,
        apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4],
        apmac_addr[5]);

    struct ip_info info;
    if (wifi_get_ip_info(0, &info)) {
        len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", IP2STR(&info.ip.addr));
        len += os_sprintf(buff+len, ", \"netmask\": \"%d.%d.%d.%d\"", IP2STR(&info.netmask.addr));
        len += os_sprintf(buff+len, ", \"gateway\": \"%d.%d.%d.%d\"", IP2STR(&info.gw.addr));
        len += os_sprintf(buff+len, ", \"hostname\": \"%s\"", flashConfig.hostname);
    } else {
        len += os_sprintf(buff+len, ", \"ip\": \"-none-\"");
    }
    len += os_sprintf(buff+len, ", \"staticip\": \"%d.%d.%d.%d\"", IP2STR(&flashConfig.staticip));
    len += os_sprintf(buff+len, ", \"dhcp\": \"%s\"", flashConfig.staticip > 0 ? "off" : "on");

    return len;
}
Exemplo n.º 19
0
/******************************************************************************
 * FunctionName : wifi_handle_event_cb
 * Description  :
 * Parameters   : none
 * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR wifi_handle_event_cb(System_Event_t *evt)
{
	int i;
	os_printf("WiFi event %x\n", evt->event);
	switch (evt->event) {
		case EVENT_SOFTAPMODE_PROBEREQRECVED:
			os_printf("Probe Request (MAC:" MACSTR ", RSSI:%d)\n",
					MAC2STR(evt->event_info.ap_probereqrecved.mac),
					evt->event_info.ap_probereqrecved.rssi);
			break;
		case EVENT_STAMODE_CONNECTED:
			os_printf("Connect to ssid %s, channel %d\n",
					evt->event_info.connected.ssid,
					evt->event_info.connected.channel);
			break;
		case EVENT_STAMODE_DISCONNECTED:
			os_printf("Disconnect from ssid %s, reason %d\n",
					evt->event_info.disconnected.ssid,
					evt->event_info.disconnected.reason);
			break;
		case EVENT_STAMODE_AUTHMODE_CHANGE:
			os_printf("New AuthMode: %d -> %d\n",
					evt->event_info.auth_change.old_mode,
					evt->event_info.auth_change.new_mode);
			break;
		case EVENT_STAMODE_GOT_IP:
			os_printf("Station ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR "\n",
					IP2STR(&evt->event_info.got_ip.ip),
					IP2STR(&evt->event_info.got_ip.mask),
					IP2STR(&evt->event_info.got_ip.gw));
			break;
		case EVENT_SOFTAPMODE_STACONNECTED:
			i = wifi_softap_get_station_num(); // Number count of stations which connected to ESP8266 soft-AP
			os_printf("Station[%u]: " MACSTR " join, AID = %d\n",
					i,
					MAC2STR(evt->event_info.sta_connected.mac),
					evt->event_info.sta_connected.aid);
			break;
		case EVENT_SOFTAPMODE_STADISCONNECTED:
			i = wifi_softap_get_station_num();
			os_printf("Station[%u]: " MACSTR " leave, AID = %d\n",
					i,
					MAC2STR(evt->event_info.sta_disconnected.mac),
					evt->event_info.sta_disconnected.aid);
			break;
		case EVENT_STAMODE_DHCP_TIMEOUT:
			os_printf("DHCP timeot\n");
			break;
/*		default:
			break; */
		}
}
Exemplo n.º 20
0
void wifi_handle_event_cb(System_Event_t *evt) {
    printf("event %x\n", evt->event_id);
    switch (evt->event_id) {
        case EVENT_STAMODE_CONNECTED:
            printf("connect to ssid %s, channel %d\n",
                   evt->event_info.connected.ssid,
                   evt->event_info.connected.channel);
            break;
        case EVENT_STAMODE_DISCONNECTED:
            printf("disconnect from ssid %s, reason %d\n",
                   evt->event_info.disconnected.ssid,
                   evt->event_info.disconnected.reason);

            if (connected) {
                connected = false;
                on_disconnect();
            }

            break;
        case EVENT_STAMODE_AUTHMODE_CHANGE:
            printf("mode: %d -> %d\n",
                   evt->event_info.auth_change.old_mode,
                   evt->event_info.auth_change.new_mode);
            break;
        case EVENT_STAMODE_GOT_IP:
            printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
                   IP2STR(&evt->event_info.got_ip.ip),
                   IP2STR(&evt->event_info.got_ip.mask),
                   IP2STR(&evt->event_info.got_ip.gw));
            printf("\n");

            first_connect = false;
            connected = true;

            on_connect();

            break;
        case EVENT_SOFTAPMODE_STACONNECTED:
            printf("station: " MACSTR "join, AID = %d\n",
                   MAC2STR(evt->event_info.sta_connected.mac),
                   evt->event_info.sta_connected.aid);
            break;
        case EVENT_SOFTAPMODE_STADISCONNECTED:
            printf("station: " MACSTR "leave, AID = %d\n", MAC2STR(evt->event_info.sta_disconnected.mac),
                   evt->event_info.sta_disconnected.aid);
            break;
        default:
            break;
    }
}
Exemplo n.º 21
0
/*
 * 函数:wifi_handle_event_cb
 * 参数:System_Event_t *evt
 * 说明:WiFi事件回调
 */
void ICACHE_FLASH_ATTR
wifi_handle_event_cb(System_Event_t *evt)
{
  os_printf("event %x\n", evt->event);

  switch (evt->event) {
      case EVENT_STAMODE_CONNECTED:
        os_printf("connect to ssid %s, channel %d\n",
          evt->event_info.connected.ssid,
          evt->event_info.connected.channel);
        break;
      case EVENT_STAMODE_DISCONNECTED:
        os_printf("disconnect from ssid %s, reason %d\n",
          evt->event_info.disconnected.ssid,
          evt->event_info.disconnected.reason);
        break;
      case EVENT_STAMODE_AUTHMODE_CHANGE:
          os_printf("mode: %d -> %d\n",
          evt->event_info.auth_change.old_mode,
          evt->event_info.auth_change.new_mode);
          break;
      case EVENT_STAMODE_GOT_IP:
        os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
                IP2STR(&evt->event_info.got_ip.ip),
                IP2STR(&evt->event_info.got_ip.mask),
                IP2STR(&evt->event_info.got_ip.gw));
        os_printf("\n");

        // TODO:
        // WiFi连接后并获取IP后建立TCP连接
        tcp_client_init(HOST, PORT);


        break;
      case EVENT_SOFTAPMODE_STACONNECTED:
          os_printf("station: " MACSTR "join, AID = %d\n",
        MAC2STR(evt->event_info.sta_connected.mac),
        evt->event_info.sta_connected.aid);
          break;
      case EVENT_SOFTAPMODE_STADISCONNECTED:
          os_printf("station: " MACSTR "leave, AID = %d\n",
        MAC2STR(evt->event_info.sta_disconnected.mac),
        evt->event_info.sta_disconnected.aid);
          break;
      default:
        break;
  }
}
Exemplo n.º 22
0
//write mesh reconn info to flash
void ICACHE_FLASH_ATTR
debug_FlashSvMeshReconInfo(char* time_str,sint8 err)
{

    uint8 reconInfo[200];
	int len;
	os_memset(reconInfo,0,sizeof(reconInfo));
	
    struct ip_info ipconfig;
    wifi_get_ip_info(STATION_IF, &ipconfig);



	len = os_sprintf(reconInfo,"MESH RECONN AT %s,ERR:%d,IP:"IPSTR";\r\n",time_str,err,IP2STR(&(ipconfig.ip)));
	
    //int len = os_strlen(reconInfo);
	char* ptmp = reconInfo + len;
	
    uint8 pad_len = 0;
    if(len%4 != 0){
        pad_len = 4 - (len%4);
        os_memcpy(ptmp,"   ",pad_len);
    }
    len += pad_len;

	
	ESP_DBG("%s\r\n",reconInfo);
    debug_PrintToFlash(reconInfo,len,&FlashDebugBufParam,Flash_DEBUG_INFO_ADDR);


}
Exemplo n.º 23
0
static void ICACHE_FLASH_ATTR dns_callback(const char * hostname, ip_addr_t * addr, void * arg)
{
	request_args * req = (request_args *)arg;

	if (addr == NULL) {
		os_printf("DNS failed %s\n", hostname);
	}
	else {
		PRINTF("DNS found %s " IPSTR "\n", hostname, IP2STR(addr));

		struct espconn * conn = (struct espconn *)os_malloc(sizeof(struct espconn));
		conn->type = ESPCONN_TCP;
		conn->state = ESPCONN_NONE;
		conn->proto.tcp = (esp_tcp *)os_malloc(sizeof(esp_tcp));
		conn->proto.tcp->local_port = espconn_port();
		conn->proto.tcp->remote_port = req->port;
		conn->reverse = req;

		os_memcpy(conn->proto.tcp->remote_ip, addr, 4);

		espconn_regist_connectcb(conn, connect_callback);
		espconn_regist_disconcb(conn, disconnect_callback);

		// TODO: consider using espconn_regist_reconcb (for timeouts?)
		// cf esp8266_sdk_v0.9.1/examples/at/user/at_ipCmd.c  (TCP ARQ retransmission?)

		espconn_connect(conn);
	}
}
Exemplo n.º 24
0
AVRISPState_t ESP8266AVRISP::update() {
    switch (_state) {
        case AVRISP_STATE_IDLE: {
            if (_server.hasClient()) {
                _client = _server.available();
                _client.setNoDelay(true);
                ip_addr_t lip;
                lip.addr = _client.remoteIP();
                AVRISP_DEBUG("client connect %d.%d.%d.%d:%d", IP2STR(&lip), _client.remotePort());
                _client.setTimeout(100); // for getch()
                _state = AVRISP_STATE_PENDING;
                _reject_incoming();
            }
            break;
        }
        case AVRISP_STATE_PENDING:
        case AVRISP_STATE_ACTIVE: {
            // handle disconnect
            if (!_client.connected()) {
                _client.stop();
                AVRISP_DEBUG("client disconnect");
                if (pmode) {
                    SPI.end();
                    pmode = 0;
                }
                setReset(_reset_state);
                _state = AVRISP_STATE_IDLE;
            } else {
                _reject_incoming();
            }
            break;
        }
    }
    return _state;
}
Exemplo n.º 25
0
// Lua: table = wifi.ap.getclient()
static int wifi_ap_listclient( lua_State* L )
{
  if (wifi_get_opmode() == STATION_MODE)
  {
    return luaL_error( L, "Can't list client in STATION_MODE mode" );
  }

  char temp[64];

  lua_newtable(L);

  struct station_info * station = wifi_softap_get_station_info();
  struct station_info * next_station;
  while (station != NULL)
  {
    c_sprintf(temp, IPSTR, IP2STR(&station->ip));
    lua_pushstring(L, temp);

    c_sprintf(temp, MACSTR, MAC2STR(station->bssid));
    lua_setfield(L, -2, temp);

    next_station = STAILQ_NEXT(station, next);
    c_free(station);
    station = next_station;
  }

  return 1;
}
Exemplo n.º 26
0
void ICACHE_FLASH_ATTR
at_setupCmdCifsr(uint8_t id, char *pPara)
{
  struct ip_info pTempIp;
  int8_t len;
  char ipTemp[64];
//  char temp[64];

  if(at_wifiMode == STATION_MODE)
  {
    at_backError;
    return;
  }
  pPara = strchr(pPara, '\"');
  len = at_dataStrCpy(ipTemp, pPara, 32);
  if(len == -1)
  {
    uart0_sendStr("IP ERROR\r\n");
    return;
  }

  wifi_get_ip_info(0x01, &pTempIp);
  pTempIp.ip.addr = ipaddr_addr(ipTemp);

  os_printf("%d.%d.%d.%d\r\n",
                 IP2STR(&pTempIp.ip));

  if(!wifi_set_ip_info(0x01, &pTempIp))
  {
    at_backError;
    return;
  }
  at_backOk;
  return;
}
Exemplo n.º 27
0
/**
  * @brief  Tcp client connect success callback function.
  * @param  arg: contain the ip link information
  * @retval None
  */
static void ICACHE_FLASH_ATTR
at_upDate_connect_cb(void *arg)
{
  struct espconn *pespconn = (struct espconn *)arg;
  uint8_t user_bin[9] = {0};
//  uint8_t devkey[41] = {0};
  char *temp;

  uart0_sendStr("+CIPUPDATE:2\r\n");

//  user_esp_platform_load_param(&esp_param);
//  os_memcpy(devkey, esp_param.devkey, 40);

  espconn_regist_disconcb(pespconn, at_upDate_discon_cb);
  espconn_regist_recvcb(pespconn, at_upDate_recv);////////
  espconn_regist_sentcb(pespconn, at_upDate_sent_cb);

//  os_printf("at_upDate_connect_cb %p\r\n", arg);

  temp = (uint8 *) os_zalloc(512);

  os_sprintf(temp,"GET /v1/device/rom/?is_format_simple=true HTTP/1.0\r\nHost: "IPSTR":%d\r\n"pheadbuffer"",
             IP2STR(pespconn->proto.tcp->remote_ip),
             80, KEY);

  espconn_sent(pespconn, temp, os_strlen(temp));
  os_free(temp);
/////////////////////////
}
Exemplo n.º 28
0
// Status check function
void check_timerfunc(void *arg) {
    struct ip_info ipConfig;
    wifi_get_ip_info(STATION_IF, &ipConfig);
    if (ipConfig.ip.addr != 0) {
        connection_status = CONNECTION_CONNECTED;
        //ets_uart_printf("[check_timerfunc] Connected? ");
        ets_uart_printf("C %d.%d.%d.%d\r\n", IP2STR(&ipConfig.ip));
        //ets_uart_printf("C");

        if (mode == MODE_AP) {
            // Just Station and no AP
            setup_stationmode();
            // Turn off HTTP server
            stop_server();
        }

    } else if (connection_status == CONNECTION_CONNECTING) {
        ets_uart_printf("X");
        //print("[check_timerfunc] No IP");
    } else {
        ets_uart_printf("U");
        if (mode != MODE_AP) {
            // Setup AP and Server
            setup_ap();
            setup_server();
        }
    }
}
static void FUNCTION_ATTRIBUTE dns_callback(const char * hostname, ip_addr_t * addr, void * arg)
{
	//request_args * req = (request_args *)arg;

	if (addr == NULL)
	{
		PRINTF("DNS failed %s\n", hostname);
		http_exit(DNS_FAIL);
	}

	else
	{
		PRINTF("DNS found %s " IPSTR "\n", hostname, IP2STR(addr));
		conn = (struct espconn *)os_malloc(sizeof(struct espconn));
		conn->type = ESPCONN_TCP;
		conn->state = ESPCONN_NONE;
		conn->proto.tcp = (esp_tcp *)os_malloc(sizeof(esp_tcp));
		conn->proto.tcp->local_port = espconn_port();
		conn->proto.tcp->remote_port = http_port;
		os_memcpy(conn->proto.tcp->remote_ip, addr, 4);
		espconn_regist_connectcb(conn, connect_callback);
		espconn_regist_disconcb(conn, disconnect_callback);
		espconn_regist_reconcb(conn, reconnect_callback);
		PRINTF("start connect http server\n");
		// TODO: consider using espconn_regist_reconcb (for timeouts?)
		// cf esp8266_sdk_v0.9.1/examples/at/user/at_ipCmd.c  (TCP ARQ retransmission?)
		espconn_secure_connect(conn);
	}
}
Exemplo n.º 30
0
CALLR  CtxDns::_get_hostname()
{
    DnsCommon dns;

    if(__dnsssl->deque_host(_cliip, _hdr.asll(), dns))
    {
        LOGT(" found  host from dns[" << IP2STR(_cliip) << "]<="<< dns.hostname);
        if(dns.domainip==0)
        {
             _raddr = __db->dnsgetip(dns.hostname);
        }
        else
        {
            _raddr = SADDR_46(dns.domainip);
        }
        _raddr.set_port(_pconf->conport ? _pconf->conport : 80);
        _set_rhost(_raddr);
        LOGD(_cliip.c_str() << " --r/dns--> "<< _raddr.c_str() );
        return _host_connect(_r_socket);
    }
    else if(!_pconf->redirect.empty())
    {    //fallback
        _set_rhost(_pconf->toaddr, 0, 0);
        LOGD(_cliip.c_str() << " --r/cfg--> "<< _raddr.c_str() );
        return _host_connect(_r_socket);
    }
    LOGE("No destination host found in queued hosts, neither in configuration. Connection closed");
    return R_KILL;
}