Exemple #1
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; */
		}
}
Exemple #2
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "getConnectedStations",
  "generate" : "jswrap_ESP8266WiFi_getConnectedStations",
  "return"   : ["JsVar","An array of connected stations."]
}*/
JsVar *jswrap_ESP8266WiFi_getConnectedStations() {
  uint8 stationCount = wifi_softap_get_station_num();
  struct station_info *stationInfo = wifi_softap_get_station_info();
  JsVar *jsArray = jsvNewArray(NULL, 0);
  if (stationInfo != NULL) {
    while (stationInfo != NULL) {
      os_printf("Station IP: %d.%d.%d.%d\n", IP2STR(&(stationInfo->ip)));
      JsVar *jsStation = jsvNewWithFlags(JSV_OBJECT);
      jsvUnLock(jsvObjectSetChild(jsStation, "ip", jsvNewFromInteger(stationInfo->ip.addr)));
      jsvArrayPush(jsArray, jsStation);
      stationInfo = STAILQ_NEXT(stationInfo, next);
    }
    wifi_softap_free_station_info();
  }
  return jsArray;
}
LOCAL void ICACHE_FLASH_ATTR initDone() {
    wifi_set_opmode_current(SOFTAP_MODE);
    struct softap_config config; 
    os_strcpy(config.ssid, "Free WiFi - Coursety @threatbutt");
    os_strcpy(config.password, "");
    config.ssid_len = 0;
    config.authmode = AUTH_OPEN;
    config.ssid_hidden = 0;
    config.max_connection = 4;
    wifi_softap_set_config_current(&config);
    wifi_softap_dhcps_start();
    uint8 stationCount = wifi_softap_get_station_num(); 
    struct station_info currentstation;


} // End of initDone
void ICACHE_FLASH_ATTR get_wifi2_status(const int8_t cid, const GetWifi2Status *data) {
	gw2sr.header = data->header;
	gw2sr.header.length = sizeof(GetWifi2StatusReturn);

	struct ip_info info;
	wifi_get_ip_info(STATION_IF, &info);
	gw2sr.client_ip[0] = ip4_addr1(&info.ip);
	gw2sr.client_ip[1] = ip4_addr2(&info.ip);
	gw2sr.client_ip[2] = ip4_addr3(&info.ip);
	gw2sr.client_ip[3] = ip4_addr4(&info.ip);
	gw2sr.client_subnet_mask[0] = ip4_addr1(&info.netmask);
	gw2sr.client_subnet_mask[1] = ip4_addr2(&info.netmask);
	gw2sr.client_subnet_mask[2] = ip4_addr3(&info.netmask);
	gw2sr.client_subnet_mask[3] = ip4_addr4(&info.netmask);
	gw2sr.client_gateway[0] = ip4_addr1(&info.gw);
	gw2sr.client_gateway[1] = ip4_addr2(&info.gw);
	gw2sr.client_gateway[2] = ip4_addr3(&info.gw);
	gw2sr.client_gateway[3] = ip4_addr4(&info.gw);

	wifi_get_ip_info(SOFTAP_IF, &info);
	gw2sr.ap_ip[0] = ip4_addr1(&info.ip);
	gw2sr.ap_ip[1] = ip4_addr2(&info.ip);
	gw2sr.ap_ip[2] = ip4_addr3(&info.ip);
	gw2sr.ap_ip[3] = ip4_addr4(&info.ip);
	gw2sr.ap_subnet_mask[0] = ip4_addr1(&info.netmask);
	gw2sr.ap_subnet_mask[1] = ip4_addr2(&info.netmask);
	gw2sr.ap_subnet_mask[2] = ip4_addr3(&info.netmask);
	gw2sr.ap_subnet_mask[3] = ip4_addr4(&info.netmask);
	gw2sr.ap_gateway[0] = ip4_addr1(&info.gw);
	gw2sr.ap_gateway[1] = ip4_addr2(&info.gw);
	gw2sr.ap_gateway[2] = ip4_addr3(&info.gw);
	gw2sr.ap_gateway[3] = ip4_addr4(&info.gw);

	wifi_get_macaddr(STATION_IF, gw2sr.client_mac_address);
	wifi_get_macaddr(SOFTAP_IF, gw2sr.ap_mac_address);

	gw2sr.client_enabled = configuration_current.client_enable;
	gw2sr.ap_enabled = configuration_current.ap_enable;

	gw2sr.client_rssi = wifi_station_get_rssi();

	gw2sr.client_status = wifi_station_get_connect_status();

	gw2sr.ap_connected_count = wifi_softap_get_station_num();

	com_send(&gw2sr, sizeof(GetWifi2StatusReturn), cid);
}
Exemple #5
0
/**
 * Get the count of the Station / client that are connected to the softAP interface
 * @return Stations count
 */
uint8_t ESP8266WiFiAPClass::softAPgetStationNum() {
    return wifi_softap_get_station_num();
}