Exemple #1
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "getDHCPHostname",
  "generate" : "jswrap_ESP8266WiFi_getDHCPHostname",
  "return"   : ["JsVar", "The current DHCP hostname."]
}
 * Get the current DHCP hostname.
*/
JsVar *jswrap_ESP8266WiFi_getDHCPHostname() {
  char *hostname = wifi_station_get_hostname();
  if (hostname == NULL) {
    hostname = "";
  }
  return jsvNewFromString(hostname);
}
void ICACHE_FLASH_ATTR get_wifi2_mesh_station_status(const int8_t cid,
	const GetWifi2MeshStationStatus *data) {
		uint8_t mac[6];
		char *hostname_ptr;
		struct ip_info info_ipv4;
		struct station_config *config_st;

		os_bzero(&gw2mssr.header, sizeof(gw2mssr.header));

		gw2mssr.header = data->header;
		gw2mssr.header.length = sizeof(GetWifi2MeshStationStatusReturn);

		if((wifi_get_ip_info(STATION_IF, &info_ipv4)) && (wifi_get_macaddr(STATION_IF, mac))) {
			hostname_ptr = wifi_station_get_hostname();

			os_bzero(gw2mssr.hostname, sizeof(gw2mssr.hostname));
			os_memcpy(gw2mssr.hostname, hostname_ptr, sizeof(gw2mssr.hostname));

			os_bzero(gw2mssr.ip, sizeof(gw2mssr.ip));
			os_memcpy(gw2mssr.ip, (uint8_t *)&info_ipv4.ip.addr, sizeof(info_ipv4.ip.addr));

			os_bzero(gw2mssr.sub, sizeof(gw2mssr.sub));
			os_memcpy(gw2mssr.sub, (uint8_t *)&info_ipv4.netmask.addr, sizeof(info_ipv4.netmask.addr));

			os_bzero(gw2mssr.gw, sizeof(gw2mssr.gw));
			os_memcpy(gw2mssr.gw, (uint8_t *)&info_ipv4.gw.addr, sizeof(info_ipv4.gw.addr));

			os_bzero(gw2mssr.mac, sizeof(gw2mssr.mac));
			os_memcpy(gw2mssr.mac, mac, sizeof(mac));
		}

		com_send(&gw2mssr, sizeof(GetWifi2MeshStationStatusReturn), cid);
}
Exemple #3
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");
  }
}
Exemple #4
0
static void ICACHE_FLASH_ATTR startUp() {
	TESTP("\n%s ( %s - %s ) starting ...\n", "MQTT Bridge", wifi_station_get_hostname(), version);
	INFOP("wifi_get_phy_mode = %d\n", wifi_get_phy_mode());

//	os_timer_disarm(&uartTimer);
//	os_timer_setfn(&uartTimer, (os_timer_func_t *) uartTimerCb, (void *) 0);
//	os_timer_arm(&uartTimer, 10 * 1000, true);

	if ( !system_os_task(backgroundTask, USER_TASK_PRIO_1, taskQueue, QUEUE_SIZE))
		ERRORP("Can't set up background task\n");
	lastAction = INIT_DONE;
}
void ICACHE_FLASH_ATTR mb_make_full_device_name(char *p_dest, char *p_str, int maxlen) {
	int len2 = os_strlen(p_str);
	
	char *p_hostname = wifi_station_get_hostname();	
	os_strncpy(p_dest, p_hostname, maxlen);
	int len1 = os_strlen(p_dest);
	
	int len2max = maxlen - (len1 + len2) - 1;
	
	if (len2max > 1) {
		os_strcat(p_dest, ".");
		os_strcat(p_dest, p_str);
	}
	
	int len3 = os_strlen(p_dest);
}
Exemple #6
0
/**
 * Set ESP8266 station DHCP hostname
 * @param aHostname max length:24
 * @return ok
 */
bool ESP8266WiFiSTAClass::hostname(const char* aHostname) {
  /*
  vvvv RFC952 vvvv
  ASSUMPTIONS
  1. A "name" (Net, Host, Gateway, or Domain name) is a text string up
   to 24 characters drawn from the alphabet (A-Z), digits (0-9), minus
   sign (-), and period (.).  Note that periods are only allowed when
   they serve to delimit components of "domain style names". (See
   RFC-921, "Domain Name System Implementation Schedule", for
   background).  No blank or space characters are permitted as part of a
   name. No distinction is made between upper and lower case.  The first
   character must be an alpha character.  The last character must not be
   a minus sign or period.  A host which serves as a GATEWAY should have
   "-GATEWAY" or "-GW" as part of its name.  Hosts which do not serve as
   Internet gateways should not use "-GATEWAY" and "-GW" as part of
   their names. A host which is a TAC should have "-TAC" as the last
   part of its host name, if it is a DoD host.  Single character names
   or nicknames are not allowed.
  ^^^^ RFC952 ^^^^

  - 24 chars max
  - only a..z A..Z 0..9 '-'
  - no '-' as last char
  */

    size_t len = strlen(aHostname);

    if (len == 0 || len > 32) {
        // nonos-sdk limit is 32
        // (dhcp hostname option minimum size is ~60)
        DEBUG_WIFI_GENERIC("WiFi.(set)hostname(): empty or large(>32) name\n");
        return false;
    }

    // check RFC compliance
    bool compliant = (len <= 24);
    for (size_t i = 0; compliant && i < len; i++)
        if (!isalnum(aHostname[i]) && aHostname[i] != '-')
            compliant = false;
    if (aHostname[len - 1] == '-')
        compliant = false;

    if (!compliant) {
        DEBUG_WIFI_GENERIC("hostname '%s' is not compliant with RFC952\n", aHostname);
    }

    bool ret = wifi_station_set_hostname(aHostname);
    if (!ret) {
        DEBUG_WIFI_GENERIC("WiFi.hostname(%s): wifi_station_set_hostname() failed\n", aHostname);
        return false;
    }

    // now we should inform dhcp server for this change, using lwip_renew()
    // looping through all existing interface
    // harmless for AP, also compatible with ethernet adapters (to come)
    for (netif* intf = netif_list; intf; intf = intf->next) {

        // unconditionally update all known interfaces
#if LWIP_VERSION_MAJOR == 1
        intf->hostname = (char*)wifi_station_get_hostname();
#else
        intf->hostname = wifi_station_get_hostname();
#endif

        if (netif_dhcp_data(intf) != nullptr) {
            // renew already started DHCP leases
            err_t lwipret = dhcp_renew(intf);
            if (lwipret != ERR_OK) {
                DEBUG_WIFI_GENERIC("WiFi.hostname(%s): lwIP error %d on interface %c%c (index %d)\n",
                                   intf->hostname, (int)lwipret, intf->name[0], intf->name[1], intf->num);
                ret = false;
            }
        }
    }

    return ret && compliant;
}
Exemple #7
0
/**
 * Get ESP8266 station DHCP hostname
 * @return hostname
 */
String ESP8266WiFiSTAClass::hostname(void) {
    return wifi_station_get_hostname();
}
Exemple #8
0
int http_wifi_api_get_info(http_connection *c)
{
    CGI_WIFI_DBG("http_wifi_api_get_info\n");

    //wait for whole body
    if(c->state <HTTPD_STATE_BODY_END) {
        return HTTPD_CGI_MORE;
    }

    api_cgi_status * status = c->cgi.data;

    if(status==NULL) { //first call, send headers

        status = (api_cgi_status*)os_malloc(sizeof(api_cgi_status));
        status->state=1;
        c->cgi.data=status;

        http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE);
        http_response_OK(c);

        return HTTPD_CGI_MORE;
    }
    else if(status->state==1)
    {
        //json data
        char mac[20];
        wifi_station_get_config(&wifi_status.station_config);
        char *wifistatus = "unknown";
        uint8_t c_status = wifi_station_get_connect_status();
        if (c_status >= 0 && c_status < sizeof(connStatuses)) wifistatus = connStatuses[c_status];
        int p = wifi_get_phy_mode();
        char *phy = wifiPhy[p&3];
        sint8 rssi = wifi_station_get_rssi();
        if (rssi > 0) rssi = 0;
        uint8_t op = wifi_get_opmode() & 0x3;
        char *warn = wifiWarn[op];
        uint8 mac_addr[6];
        wifi_get_macaddr(0, mac_addr);
        uint8_t chan = wifi_get_channel();

        char *hostname = wifi_station_get_hostname();
        os_sprintf(mac,"%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1],
                   mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);

        cJSON *root = cJSON_CreateObject();
        cJSON_AddNumberToObject(root,"mode",wifi_get_opmode());
        cJSON_AddStringToObject(root,"modechange", MODECHANGE);
        cJSON_AddStringToObject(root,"ssid", (const char *)wifi_status.station_config.ssid);
        cJSON_AddStringToObject(root,"status", (const char *)wifistatus);
        cJSON_AddStringToObject(root,"phy", (const char *)phy);
        cJSON_AddNumberToObject(root,"rssi", rssi);
        cJSON_AddStringToObject(root,"warn", (const char *)warn);
        cJSON_AddStringToObject(root,"mac", (const char *)mac);
        cJSON_AddNumberToObject(root,"chan", chan);
        cJSON_AddStringToObject(root,"hostname", (const char *)hostname);
        cJSON_AddStringToObject(root,"domain", (const char *)INTERFACE_DOMAIN);

        // got ip
        if(c_status==5)
        {
            struct ip_info ip;
            wifi_get_ip_info(0x0,&ip);
            char *ip_str = (char*)ipaddr_ntoa(&ip.ip);
            cJSON_AddStringToObject(root,"ip",ip_str);
        }
        else {
            cJSON_AddStringToObject(root,"ip","");
        }

        http_write_json(c,root);
        cJSON_Delete(root);

        status->state=99;
        return HTTPD_CGI_MORE;
    }
    else
    {
        os_free(c->cgi.data);
        return HTTPD_CGI_DONE;
    }
}
String ESP8266WiFiClass::hostname(void) {
    return String(wifi_station_get_hostname());
}
Exemple #10
0
void notmain(void) {
	_output_type output_type = OUTPUT_TYPE_MONITOR;
	uint8_t mac_address[6] ALIGNED;
	struct ip_info ip_config;
	E131Params e131params;
	DMXParams dmxparams;
	uuid_t uuid;
	char uuid_str[UUID_STRING_LENGTH + 1] ALIGNED;

	hardware_init();

	(void) e131params.Load();

	if (e131params.isHaveCustomCid()) {
		memcpy(uuid_str, e131params.GetCidString(), UUID_STRING_LENGTH);
		uuid_str[UUID_STRING_LENGTH] = '\0';
		uuid_parse((const char *)uuid_str, uuid);
	} else {
		hardware_uuid(uuid);
		uuid_unparse(uuid, uuid_str);
	}

	output_type = e131params.GetOutputType();

	if (output_type == OUTPUT_TYPE_MONITOR) {
		//
	} else {
		output_type = OUTPUT_TYPE_DMX;
		(void) dmxparams.Load();
	}

	printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("WiFi sACN E.131 DMX Out / Real-time DMX Monitor");

	console_set_top_row(3);

	(void) ap_params_init();
	const char *ap_password = ap_params_get_password();

	hardware_watchdog_init();

	console_status(CONSOLE_YELLOW, "Starting Wifi ...");

	wifi_init(ap_password);

	hardware_watchdog_stop();

	printf("ESP8266 information\n");
	printf(" SDK      : %s\n", system_get_sdk_version());
	printf(" Firmware : %s\n\n", wifi_get_firmware_version());

	if (network_params_init()) {
		console_status(CONSOLE_YELLOW, "Changing to Station mode ...");
		if (network_params_is_use_dhcp()) {
			wifi_station(network_params_get_ssid(), network_params_get_password());
		} else {
			ip_config.ip.addr = network_params_get_ip_address();
			ip_config.netmask.addr = network_params_get_net_mask();
			ip_config.gw.addr = network_params_get_default_gateway();
			wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config);
		}
	}

	const _wifi_mode opmode = wifi_get_opmode();

	if (opmode == WIFI_STA) {
		printf("WiFi mode : Station\n");
	} else {
		printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
	}

	if (wifi_get_macaddr(mac_address)) {
		printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
	} else {
		console_error("wifi_get_macaddr");
	}

	printf(" Hostname    : %s\n", wifi_station_get_hostname());

	if (wifi_get_ip_info(&ip_config)) {
		printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
		printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
		printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));
		if (opmode == WIFI_STA) {
			const _wifi_station_status status = wifi_station_get_connect_status();
			printf("      Status : %s\n", wifi_station_status(status));
			if (status != WIFI_STATION_GOT_IP){
				console_error("Not connected!");
				for(;;);
			}
		}
	} else {
		console_error("wifi_get_ip_info");
	}

	if (fota_params_init()) {
		console_newline();
		fota(fota_params_get_server());
		for(;;);
	}

	console_status(CONSOLE_YELLOW, "Starting UDP ...");
	udp_begin(E131_DEFAULT_PORT);

	console_status(CONSOLE_YELLOW, "Join group ...");

	uint32_t group_ip;
	(void)inet_aton("239.255.0.0", &group_ip);
	const uint16_t universe = e131params.GetUniverse();
	group_ip = group_ip | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF) << 24)) | ((uint32_t)(((uint32_t)universe & (uint32_t)0xFF00) << 8));
	udp_joingroup(group_ip);

	E131Bridge bridge;
	DMXSend dmx;
	DMXMonitor monitor;

	bridge.setCid(uuid);
	bridge.setUniverse(universe);
	bridge.setMergeMode(e131params.GetMergeMode());

	if (output_type == OUTPUT_TYPE_MONITOR) {
		bridge.SetOutput(&monitor);
		console_set_top_row(20);
	} else {
		bridge.SetOutput(&dmx);

		dmx.SetBreakTime(dmxparams.GetBreakTime());
		dmx.SetMabTime(dmxparams.GetMabTime());

		const uint8_t refresh_rate = dmxparams.GetRefreshRate();
		uint32_t period = (uint32_t) 0;

		if (refresh_rate != (uint8_t) 0) {
			period = (uint32_t) (1E6 / refresh_rate);
		}
		dmx.SetPeriodTime(period);
	}

	printf("\nBridge configuration\n");
	const uint8_t *firmware_version = bridge.GetSoftwareVersion();
	printf(" Firmware     : %d.%d\n", firmware_version[0], firmware_version[1]);
	printf(" CID          : %s\n", uuid_str);
	printf(" Universe     : %d\n", bridge.getUniverse());
	printf(" Merge mode   : %s\n", bridge.getMergeMode() == E131_MERGE_HTP ? "HTP" : "LTP");
	printf(" Multicast ip : " IPSTR "\n", IP2STR(group_ip));
	printf(" Unicast ip   : " IPSTR "\n\n", IP2STR(ip_config.ip.addr));

	if (output_type == OUTPUT_TYPE_DMX) {
		printf("DMX Send parameters\n");
		printf(" Break time   : %d\n", (int) dmx.GetBreakTime());
		printf(" MAB time     : %d\n", (int) dmx.GetMabTime());
		printf(" Refresh rate : %d\n", (int) (1E6 / dmx.GetPeriodTime()));
	}

	hardware_watchdog_init();

	console_status(CONSOLE_GREEN, "Bridge is running");

	for (;;) {
		hardware_watchdog_feed();
		(void) bridge.Run();
		led_blink();
	}
}
Exemple #11
0
void notmain(void) {
	hardware_init();

	ltc_reader_params_init();

	output.console_output = ltc_reader_params_is_console_output();
	output.lcd_output = ltc_reader_params_is_lcd_output();
	output.midi_output = ltc_reader_params_is_midi_output();
	output.artnet_output = ltc_reader_params_is_artnet_output();

	if(output.midi_output) {
		midi_send_init();
	}

	if (output.lcd_output) {
		output.lcd_output = lcd_detect();
	}

	if (output.artnet_output) {
		output.artnet_output = wifi_detect();
	}

	ltc_reader_init(&output);

	printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__);
	printf("SMPTE TimeCode LTC Reader / Converter");

	console_set_top_row(3);

	console_set_cursor(0, 12);
	console_puts("Console output : "); handle_bool(output.console_output); console_putc('\n');
	console_puts("LCD output     : "); handle_bool(output.lcd_output); console_putc('\n');
	console_puts("MIDI output    : "); handle_bool(output.midi_output); console_putc('\n');
	console_puts("ArtNet output  : "); handle_bool(output.artnet_output);console_puts(" (not implemented)\n");

	if (output.artnet_output) {
		uint8_t mac_address[6];
		struct ip_info ip_config;

		(void) ap_params_init();
		const char *ap_password = ap_params_get_password();

		console_status(CONSOLE_YELLOW, "Starting Wifi ...");

		wifi_init(ap_password);

		printf("\nESP8266 information\n");
		printf(" SDK      : %s\n", system_get_sdk_version());
		printf(" Firmware : %s\n\n", wifi_get_firmware_version());

		if (network_params_init()) {
			console_status(CONSOLE_YELLOW, "Changing to Station mode ...");
			if (network_params_is_use_dhcp()) {
				wifi_station(network_params_get_ssid(), network_params_get_password());
			} else {
				ip_config.ip.addr = network_params_get_ip_address();
				ip_config.netmask.addr = network_params_get_net_mask();
				ip_config.gw.addr = network_params_get_default_gateway();
				wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config);
			}
		}

		const _wifi_mode opmode = wifi_get_opmode();

		if (opmode == WIFI_STA) {
			printf("WiFi mode : Station\n");
		} else {
			printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK");
		}

		if (wifi_get_macaddr(mac_address)) {
			printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address));
		} else {
			console_error("wifi_get_macaddr");
		}

		printf(" Hostname    : %s\n", wifi_station_get_hostname());

		if (wifi_get_ip_info(&ip_config)) {
			printf(" IP-address  : " IPSTR "\n", IP2STR(ip_config.ip.addr));
			printf(" Netmask     : " IPSTR "\n", IP2STR(ip_config.netmask.addr));
			printf(" Gateway     : " IPSTR "\n", IP2STR(ip_config.gw.addr));
			if (opmode == WIFI_STA) {
				const _wifi_station_status status = wifi_station_get_connect_status();
				printf("      Status : %s\n", wifi_station_status(status));
				if (status != WIFI_STATION_GOT_IP){
					console_error("Not connected!");
					for(;;);
				}
			}
		} else {
			console_error("wifi_get_ip_info");
		}

		console_status(CONSOLE_YELLOW, "Starting UDP ...");
		udp_begin(6454);

		console_status(CONSOLE_GREEN, "Wifi is started");
	}

	for (;;) {
		ltc_reader();
	}
}