void AppWIFI::init() { wifi_set_sleep_type(NONE_SLEEP_T); //don`t enable/disable again to save eeprom cycles if(!WifiStation.isEnabled()) { debugapp("AppWIFI::init enable WifiStation"); WifiStation.enable(true, true); } if(WifiAccessPoint.isEnabled()) { debugapp("AppWIFI::init WifiAccessPoint disablw"); WifiAccessPoint.enable(false, true); } _con_ctr = 0; if(app.isFirstRun()) { debugapp("AppWIFI::init initial run - setting up AP"); app.cfg.network.connection.mdnshostname = String(DEFAULT_AP_SSIDPREFIX) + String(system_get_chip_id()); app.cfg.network.ap.ssid = String(DEFAULT_AP_SSIDPREFIX) + String(system_get_chip_id()); app.cfg.save(); WifiAccessPoint.setIP(_ApIP); } WifiEvents.onStationDisconnect(onStationDisconnectDelegate(&AppWIFI::_STADisconnect, this)); WifiEvents.onStationConnect(onStationConnectDelegate(&AppWIFI::_STAConnected, this)); WifiEvents.onStationGotIP(onStationGotIPDelegate(&AppWIFI::_STAGotIP, this)); if(WifiStation.getSSID() == "") { debugapp("AppWIFI::init no AP to connect to - start own AP"); // No wifi to connect to - initialize AP startAp(); // already scan for avaialble networks to speedup things later scan(); } else { //configure WifiClient if (!app.cfg.network.connection.dhcp && !app.cfg.network.connection.ip.isNull()) { debugapp("AppWIFI::init setting static ip"); if(WifiStation.isEnabledDHCP()) { debugapp("AppWIFI::init disabled dhcp"); WifiStation.enableDHCP(false); } if ( !(WifiStation.getIP() == app.cfg.network.connection.ip) || !(WifiStation.getNetworkGateway() == app.cfg.network.connection.gateway) || !(WifiStation.getNetworkMask() == app.cfg.network.connection.netmask)) { debugapp("AppWIFI::init updating ip configuration"); WifiStation.setIP(app.cfg.network.connection.ip, app.cfg.network.connection.netmask, app.cfg.network.connection.gateway); } } else { debugapp("AppWIFI::init dhcp"); if(!WifiStation.isEnabledDHCP()) { debugapp("AppWIFI::init enabling dhcp"); WifiStation.enableDHCP(true); } } } }
/** * @brief Initialize the CPU, the board and the peripherals * * This function is called by ESP8266 SDK when all system initializations * has been finished. */ void system_init(void) { LOG_INFO("\nStarting ESP8266 CPU with ID: %08x", system_get_chip_id()); LOG_INFO("\nSDK Version %s\n\n", system_get_sdk_version()); /* avoid reconnection all the time */ wifi_station_disconnect(); /* set exception handlers */ init_exceptions (); /* init random number generator */ srand(hwrand()); /* init flash drive */ extern void flash_drive_init (void); flash_drive_init(); /* trigger static peripheral initialization */ periph_init(); /* trigger board initialization */ board_init(); /* print the board config */ board_print_config(); }
void ICACHE_FLASH_ATTR connected_cloud_cb(void* param) { uint8 rcvbuf[16]; struct espconn* conn = (struct espconn*)param; os_printf("connected_cloud_cb, conn: [%p]\n", conn); client_status = STATUS_CONNECTED; //注册 断开与接收、发送的回调 espconn_regist_recvcb(conn, data_received_cb); espconn_regist_sentcb(conn, sent_cloud_cb); espconn_regist_disconcb(conn, disconnected_cloud_cb); //注册心跳回调 heart_timer* pheart = (heart_timer*)os_zalloc(sizeof(heart_timer)); ETSTimer* timer = (ETSTimer*)os_zalloc(sizeof(ETSTimer)); pheart->timer = timer; pheart->conn = conn; conn->reverse = (void*)pheart; os_timer_disarm(timer); os_timer_setfn(timer, heart_beat_cbfn, pheart); os_timer_arm(timer, 120000, 1);//两分钟一个心跳包, 重复 uint32* pchipid = (uint32*)(rcvbuf + 2); rcvbuf[0] = 7; rcvbuf[1] = 0; *pchipid = system_get_chip_id(); rcvbuf[6] = 1; espconn_sent(conn, rcvbuf, 7); os_printf("DEV RP OVER\n"); }
/* fill device info 这里设备信息需要修改对应宏定义,其中DEV_MAC和DEV_CHIPID 需要用户自己实现接口函数*/ void ICACHE_FLASH_ATTR alink_fill_deviceinfo(struct device_info *deviceinfo) { uint8 macaddr[6]; //fill main device info here strcpy(deviceinfo->name, DEV_NAME); strcpy(deviceinfo->sn, DEV_SN); strcpy(deviceinfo->key, ALINK_KEY); strcpy(deviceinfo->model, DEV_MODEL); strcpy(deviceinfo->secret, ALINK_SECRET); strcpy(deviceinfo->type, DEV_TYPE); strcpy(deviceinfo->version, DEV_VERSION); strcpy(deviceinfo->category, DEV_CATEGORY); strcpy(deviceinfo->manufacturer, DEV_MANUFACTURE); strcpy(deviceinfo->key_sandbox, ALINK_KEY_SANDBOX); strcpy(deviceinfo->secret_sandbox, ALINK_SECRET_SANDBOX); if (wifi_get_macaddr(0, macaddr)) { wsf_deb("macaddr=%02x:%02x:%02x:%02x:%02x:%02x\n", MAC2STR(macaddr)); snprintf(deviceinfo->mac, sizeof(deviceinfo->mac), "%02x:%02x:%02x:%02x:%02x:%02x", MAC2STR(macaddr)); } else strcpy(deviceinfo->mac, DEV_MAC); // if ((macaddr[4] == 0xc7) && (macaddr[5] == 0x18)) // the mac 18:fe:34:a2:c7:18 binding CHIPID "3D0044000F47333139373030" // { // strcpy(deviceinfo->cid, DEV_CHIPID); // } else { snprintf(deviceinfo->cid, sizeof(deviceinfo->cid), "%024d", system_get_chip_id()); // } wsf_deb("DEV_MODEL:%s \n", DEV_MODEL); }
void mqtt_data_cb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) { char *topicBuf = (char*)os_zalloc(topic_len+1), *dataBuf = (char*)os_zalloc(data_len+1); MQTT_Client* client = (MQTT_Client*)args; os_memcpy(topicBuf, topic, topic_len); topicBuf[topic_len] = 0; os_memcpy(dataBuf, data, data_len); dataBuf[data_len] = 0; INFO("Receive topic: %s, data: %s \r\n", topicBuf, dataBuf); // fetch if light needs to be set to on char tempreg[200]; os_sprintf(tempreg, MQTT_TOPICOUT, system_get_chip_id()); // if string matches check payload if(strcmp(topicBuf, tempreg) == 0){ // topic matches, check payload if(strcmp(dataBuf, "1-1")){ GPIO_OUTPUT_SET(13, 1); } else if(strcmp(dataBuf, "1-0")){ GPIO_OUTPUT_SET(13, 0); } } os_free(topicBuf); os_free(dataBuf); }
int ICACHE_FLASH_ATTR nixieTplWlan(HttpdConnData *connData, char *token, void **arg) { char buff[1024]; int x; static struct station_config stconf; if (token==NULL) return HTTPD_CGI_DONE; wifi_station_get_config(&stconf); os_strcpy(buff, "Unknown"); if (os_strcmp(token, "WiFiMode")==0) { x=wifi_get_opmode(); if (x==1) os_strcpy(buff, "Client"); if (x==2) os_strcpy(buff, "SoftAP"); if (x==3) os_strcpy(buff, "Client+AP"); } else if (os_strcmp(token, "currSsid")==0) { os_strcpy(buff, (char*)stconf.ssid); } else if (os_strcmp(token, "WiFiPasswd")==0) { os_strcpy(buff, (char*)stconf.password); } else if (os_strcmp(token, "DeviceID")==0) { uint8_t client_id[16]; os_sprintf(client_id, "%08X", system_get_chip_id()); os_strcpy(buff, (char*)client_id); } else if (os_strcmp(token, "WiFiapwarn")==0) { x=wifi_get_opmode(); if (x==2) { os_strcpy(buff, "<b>Can't scan in this mode.</b><a href=\"setmode.cgi?mode=3\">Go to STA+AP mode.</a>"); } else if(x==1) { os_strcpy(buff, "<a href=\"setmode.cgi?mode=3\">Go back to Client+AP mode.</a>"); } else { os_strcpy(buff, "<a href=\"setmode.cgi?mode=1\">Go to Client Only Mode</a><br /> To reset hold Button for 5 sec and release"); } } httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
/****************************************************************************** * FunctionName : mesh_SetSoftap * Description : If the device failed to join mesh network, open the SoftAP interface for webserver The SSID should not be the same form as that of the device in mesh network *******************************************************************************/ void ICACHE_FLASH_ATTR mesh_SetSoftap() { MESH_INFO("----------------------\r\n"); MESH_INFO("MESH ENABLE SOFTAP \r\n"); MESH_INFO("----------------------\r\n"); struct softap_config config_softap; char ssid[33]={0}; wifi_softap_get_config(&config_softap); os_memset(config_softap.password, 0, sizeof(config_softap.password)); os_memset(config_softap.ssid, 0, sizeof(config_softap.ssid)); os_sprintf(ssid,"ESP_%06X",system_get_chip_id()); os_memcpy(config_softap.ssid, ssid, os_strlen(ssid)); config_softap.ssid_len = os_strlen(ssid); config_softap.ssid_hidden = 0; config_softap.channel = wifi_get_channel(); #ifdef SOFTAP_ENCRYPT char password[33]; char macaddr[6]; os_sprintf(password, MACSTR "_%s", MAC2STR(macaddr), PASSWORD); os_memcpy(config_softap.password, password, os_strlen(password)); config_softap.authmode = AUTH_WPA_WPA2_PSK; #else os_memset(config_softap.password,0,sizeof(config_softap.password)); config_softap.authmode = AUTH_OPEN; #endif wifi_set_opmode(STATIONAP_MODE); wifi_softap_set_config(&config_softap); wifi_set_opmode(STATIONAP_MODE); wifi_softap_get_config(&config_softap); MESH_INFO("SSID: %s \r\n",config_softap.ssid); MESH_INFO("CHANNEL: %d \r\n",config_softap.channel); MESH_INFO("-------------------------\r\n"); }
void sysinfo(void) { os_printf("SDK version: %s Chip ID=%u\n", system_get_sdk_version(), system_get_chip_id()); system_print_meminfo(); meminfo(); }
void ShowInfo() { Serial.printf("\r\nSDK: v%s\r\n", system_get_sdk_version()); Serial.printf("Free Heap: %d\r\n", system_get_free_heap_size()); Serial.printf("CPU Frequency: %d MHz\r\n", system_get_cpu_freq()); Serial.printf("System Chip ID: %x\r\n", system_get_chip_id()); Serial.printf("SPI Flash ID: %x\r\n", spi_flash_get_id()); //Serial.printf("SPI Flash Size: %d\r\n", (1 << ((spi_flash_get_id() >> 16) & 0xff))); }
void user_init(void) { uart_init(BIT_RATE_230400, BIT_RATE_230400); system_set_os_print(1); // enable/disable operating system printout os_sprintf(topic_temp, MQTT_TOPICTEMP, system_get_chip_id()); os_sprintf(topic_hum, MQTT_TOPICHUM, system_get_chip_id()); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts ETS_GPIO_INTR_ATTACH(interrupt_test, 4); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4); gpio_output_set(0, 0, 0, GPIO_ID_PIN(4)); // Set GPIO12 as input GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(4)); gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_ANYEDGE); ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts config_load(); DHTInit(DHT11); MQTT_InitConnection(&mqttClient, config.mqtt_host, config.mqtt_port, config.security); MQTT_InitClient(&mqttClient, config.device_id, config.mqtt_user, config.mqtt_pass, config.mqtt_keepalive, 1); MQTT_InitLWT(&mqttClient, "lwt/", "offline", 0, 0); MQTT_OnConnected(&mqttClient, mqtt_connected_cb); MQTT_OnDisconnected(&mqttClient, mqtt_disconnected_cb); MQTT_OnPublished(&mqttClient, mqtt_published_cb); MQTT_OnData(&mqttClient, mqtt_data_cb); WIFI_Connect(config.sta_ssid, config.sta_pwd, wifi_connect_cb); os_timer_disarm(&dhtTimer); os_timer_setfn(&dhtTimer, (os_timer_func_t *)dhtCb, (void *)0); os_timer_arm(&dhtTimer, DELAY, 1); os_timer_disarm(&hbTimer); os_timer_setfn(&hbTimer, (os_timer_func_t *)application_heartbeat, (void *)0); os_timer_arm(&hbTimer, 60000, 1); INFO("\r\nSystem started ...\r\n"); }
//Init function. This is where the program enters void user_init() { uart_init(BIT_RATE_115200, BIT_RATE_115200); // set the baud rate for UART0 and UART1, I will use UART1 for debugging and UART0 for flashing os_printf("Hello !\n\r"); os_printf("Chip Id: %lu\n\r", system_get_chip_id()); //Prints chip ID os_printf("SDK Version: %s\n\r", system_get_sdk_version()); // Gets the sdk version system_init_done_cb(initDone); wifi_set_event_handler_cb(eventHandler); }
dce_result_t SECTION_ATTR dce_handle_GSN(dce_t* dce, void* group_ctx, int kind, size_t argc, arg_t* argv) { uint32_t chip_id = system_get_chip_id(); char buf[10]; sprintf(buf, "%08x", chip_id); dce_emit_information_response(dce, buf, -1); dce_emit_basic_result_code(dce, DCE_RC_OK); return DCE_OK; }
static void ICACHE_FLASH_ATTR tcp_receive_cb(void *arg, char *pData, unsigned short len) { HttpdConnData c; char bfr[100] = { 0 }; struct espconn *conn = (struct espconn*) arg; httpdParseHeader(pData, &c); TESTP("URL=%s\n", c.url); if (httpSetupMode && os_strncmp(c.url, "/setup", 5) == 0) { if (httpdFindArg(c.getArgs, "Action", bfr, sizeof(bfr)) >= 0) { TESTP("Action=%s\n", bfr); if (os_strncmp(bfr, "Update", 6) == 0) { if (httpdFindArg(c.getArgs, "MQTThost", bfr, sizeof(bfr)) >= 0) { TESTP("MQTThost=%s\n", bfr); if (7 < os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_host)) { os_strcpy(sysCfg.mqtt_host, bfr); } } if (httpdFindArg(c.getArgs, "MQTTport", bfr, sizeof(bfr)) >= 0) { TESTP("MQTTport=%s\n", bfr); if (1 <= os_strlen(bfr) && os_strlen(bfr) <= 4) { sysCfg.mqtt_port = atoi(bfr); } } if (httpdFindArg(c.getArgs, "MQTTuser", bfr, sizeof(bfr)) >= 0) { TESTP("MQTTuser=%s\n", bfr); if (0 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_user)) { os_strcpy(sysCfg.mqtt_user, bfr); } } if (httpdFindArg(c.getArgs, "MQTTpass", bfr, sizeof(bfr)) >= 0) { TESTP("MQTTpass=%s\n", bfr); if (0 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.mqtt_pass)) { os_strcpy(sysCfg.mqtt_pass, bfr); } } if (httpdFindArg(c.getArgs, "DevPrefix", bfr, sizeof(bfr)) >= 0) { TESTP("DevPrefix=%s\n", bfr); if (2 <= os_strlen(bfr) && os_strlen(bfr) < sizeof(sysCfg.deviceID_prefix)) { os_strcpy(sysCfg.deviceID_prefix, bfr); os_sprintf(sysCfg.device_id, "%s%lx", sysCfg.deviceID_prefix, system_get_chip_id()); } } if (httpdFindArg(c.getArgs, "reboot", bfr, sizeof(bfr)) >= 0) { TESTP("reboot=%s\n", bfr); if (strcmp(bfr, "yes") == 0) { reboot = true; } } CFG_dirty(); } } replyOK(conn); } else { replyFail(conn); } }
void ICACHE_FLASH_ATTR nixieSetSoftAP() { static struct softap_config config; wifi_softap_get_config(&config); INFO("Current SOFTAP APName: %s\n",config.ssid); os_sprintf(config.ssid,"Nixie_%08X", system_get_chip_id()); config.ssid_len=os_strlen(config.ssid); wifi_softap_set_config(&config); INFO("New SOFTAP APName: %s\n",config.ssid); wifi_set_opmode(3); }
void pb1Transmit(){ char tempreg[200]; os_sprintf(tempreg, MQTT_TOPICIN, system_get_chip_id()); if(GPIO_INPUT_GET(4)){ MQTT_Publish(&mqttClient, tempreg, "1-1", strlen("1-1"), 0, 0); } else { MQTT_Publish(&mqttClient, tempreg, "1-0", strlen("1-0"), 0, 0); } }
void ICACHE_FLASH_ATTR wifiConnectCb(uint8_t status) { // Use the hex encoded system_get_chip_id() value as // an unique topic (that still fits on the screen) os_sprintf(clientid, "/%0x", system_get_chip_id()); if (status == STATION_GOT_IP) { MQTT_Connect(&mqttClient); } }
void ICACHE_FLASH_ATTR dhserial_commands_uname(const char *args) { char digitBuff[32]; uart_send_line("DeviceHive ESP8266 firmware "FIRMWARE_VERSION" [Built: "__TIME__" "__DATE__"]"); uart_send_line("Created by Nikolay Khabarov."); uart_send_str("ChipID: 0x"); snprintf(digitBuff, sizeof(digitBuff), "%X", system_get_chip_id()); uart_send_str(digitBuff); uart_send_str(", SDK version: "); uart_send_str(system_get_sdk_version()); uart_send_line(""); }
static void ICACHE_FLASH_ATTR mqttConnectedCb(uint32_t *args) { DEBUG_PRINT("[MQTT]Connected\n"); MQTT_Client* client = (MQTT_Client*)args; char aux[20]; os_sprintf(aux, "echo/%d", system_get_chip_id()); MQTT_Subscribe(client, aux, 0); if (mqttConnected) mqttConnected(client); }
LOCAL void ICACHE_FLASH_ATTR info_cb(void *arg) { wdt_feed(); uart0_sendStr("System Info\r\n"); os_printf("Time=%ld\r\n", system_get_time()); os_printf("Chip id=%ld\r\n", system_get_chip_id()); os_printf("Free heap size=%ld\r\n", system_get_free_heap_size()); uart0_sendStr("Mem info:\r\n"); system_print_meminfo(); uart0_sendStr("\r\n"); }
static int node_info( lua_State* L ) { lua_pushinteger(L, NODE_VERSION_MAJOR); lua_pushinteger(L, NODE_VERSION_MINOR); lua_pushinteger(L, NODE_VERSION_REVISION); lua_pushinteger(L, system_get_chip_id()); // chip id lua_pushinteger(L, spi_flash_get_id()); // flash id lua_pushinteger(L, flash_get_size_byte() / 1024); // flash size in KB lua_pushinteger(L, flash_get_mode()); lua_pushinteger(L, flash_get_speed()); return 8; }
void mqtt_connected_cb(uint32_t *args) { MQTT_Client* client = (MQTT_Client*)args; INFO("MQTT: Connected\r\n"); char tempreg[200]; os_sprintf(tempreg, MQTT_TOPICOUT, system_get_chip_id()); MQTT_Subscribe(client, MQTT_WATCHDOG, 0); MQTT_Subscribe(client, tempreg, 1); application_heartbeat(); }
//Init function void ICACHE_FLASH_ATTR user_init() { //uart_div_modify(0, UART_CLK_FREQ / 115200); system_set_os_print(1); uart_init(BIT_RATE_115200, BIT_RATE_115200); os_printf("Hello !\n\r"); os_printf("Chip Id: %lu\n\r", system_get_chip_id()); os_printf("SDK Version: %s\n\r", system_get_sdk_version()); system_init_done_cb(initDone); wifi_set_event_handler_cb(eventHandler); }
void ICACHE_FLASH_ATTR wifiConnectCb(uint8_t status) { // Use the hex encoded system_get_chip_id() value as // an unique topic (that still fits on the screen) os_sprintf(clientid, "/%0x", system_get_chip_id()); if(status == STATION_GOT_IP){ os_printf("Connecting to MQTT server %s:%d\n", MQTT_HOST, MQTT_PORT); MQTT_Connect(&mqttClient); } else { MQTT_Disconnect(&mqttClient); } }
static int node_info( lua_State* L ) { lua_pushinteger(L, NODE_VERSION_MAJOR); lua_pushinteger(L, NODE_VERSION_MINOR); lua_pushinteger(L, NODE_VERSION_REVISION); lua_pushinteger(L, system_get_chip_id()); // chip id lua_pushinteger(L, spi_flash_get_id()); // flash id #if defined(FLASH_SAFE_API) lua_pushinteger(L, flash_safe_get_size_byte() / 1024); // flash size in KB #else lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB #endif // defined(FLASH_SAFE_API) lua_pushinteger(L, flash_rom_get_mode()); lua_pushinteger(L, flash_rom_get_speed()); return 8; }
static void ICACHE_FLASH_ATTR udp_received(void *arg, char *data, unsigned short len) { struct espconn *udpconn= (struct espconn*)arg; if (len > 5 && strncmp(data, "HAP", 3) == 0) { const char* hapServer = &data[5]; if (strcmp(settings.serverName, hapServer) != 0) return; remot_info *info = NULL; espconn_get_connection_info(udpconn, &info, 0); uint16_t port = (data[3] << 8) | data[4]; uint32_t address = *(uint32_t*)info->remote_ip; if (port == hapPort && address == hapAddress) return; hapAddress = address; hapPort = port; static bool inited = false; DEBUG_PRINT("[HAP]Discover from "IPSTR":%d\n", IP2STR(&address), port); if (inited) { MQTT_Disconnect(&mqttClient); DEBUG_PRINT("[HAP]Disconnect MQTT\n"); } char aux[20]; os_sprintf(aux, IPSTR, IP2STR(&address)); MQTT_InitConnection(&mqttClient, aux, hapPort); os_sprintf(aux, "client_%d", system_get_chip_id()); MQTT_InitClient(&mqttClient, aux, settings.mqttUser, settings.mqttPassword, MQTT_KEEPALIVE, 1); MQTT_OnConnected(&mqttClient, mqttConnectedCb); MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); MQTT_OnPublished(&mqttClient, mqttPublishedCb); MQTT_OnData(&mqttClient, mqttDataCb); MQTT_Connect(&mqttClient); inited = true; } }
void ICACHE_FLASH_ATTR CFG_Load() { os_printf("\nload (%x/%x)...\n", sizeof(sysCfg), SPI_FLASH_SEC_SIZE); spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, (uint32 *) &saveFlag, sizeof(SAVE_FLAG)); if (saveFlag.flag == 0) { spi_flash_read((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE, (uint32 *) &sysCfg, sizeof(SYSCFG)); } else { spi_flash_read((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE, (uint32 *) &sysCfg, sizeof(SYSCFG)); } if (sysCfg.cfg_holder != CFG_HOLDER) { os_memset(&sysCfg, 0x00, sizeof sysCfg); sysCfg.cfg_holder = CFG_HOLDER; os_sprintf(sysCfg.sta_ssid, "%s", STA_SSID); os_sprintf(sysCfg.sta_pwd, "%s", STA_PASS); sysCfg.sta_type = STA_TYPE; os_sprintf(sysCfg.deviceID_prefix, DEVICE_PREFIX); os_sprintf(sysCfg.device_id, "%s%lx", sysCfg.deviceID_prefix, system_get_chip_id()); os_sprintf(sysCfg.mqtt_host, "%s", MQTT_HOST); sysCfg.mqtt_port = MQTT_PORT; os_sprintf(sysCfg.mqtt_user, "%s", MQTT_USER); os_sprintf(sysCfg.mqtt_pass, "%s", MQTT_PASS); sysCfg.security = DEFAULT_SECURITY; /* default non ssl */ sysCfg.mqtt_keepalive = MQTT_KEEPALIVE; int idx; for (idx = 0; idx < MAP_SIZE; idx++) { sysCfg.mapping[idx] = idx; } for (idx = 0; idx < SETTINGS_SIZE; idx++) { sysCfg.settings[idx] = SET_MINIMUM; } sysCfg.updates = UPDATES; sysCfg.inputs = INPUTS; os_sprintf(sysCfg.deviceName, "Not Set"); os_sprintf(sysCfg.deviceLocation, "Unknown"); CFG_Save(); } }
// Handle system information variables and print their value, returns the number of // characters appended to buff int ICACHE_FLASH_ATTR printGlobalInfo(char *buff, int buflen, char *token) { if (TOKEN("si_chip_id")) { return os_sprintf(buff, "0x%x", system_get_chip_id()); } else if (TOKEN("si_freeheap")) { return os_sprintf(buff, "%dKB", system_get_free_heap_size()/1024); } else if (TOKEN("si_uptime")) { uint32 t = system_get_time() / 1000000; // in seconds return os_sprintf(buff, "%dd%dh%dm%ds", t/(24*3600), (t/(3600))%24, (t/60)%60, t%60); } else if (TOKEN("si_boot_version")) { return os_sprintf(buff, "%d", system_get_boot_version()); } else if (TOKEN("si_boot_address")) { return os_sprintf(buff, "0x%x", system_get_userbin_addr()); } else if (TOKEN("si_cpu_freq")) { return os_sprintf(buff, "%dMhz", system_get_cpu_freq()); } else { return 0; } }
void ICACHE_FLASH_ATTR show_sysinfo() { uint32 chipid = system_get_chip_id(); uint32 heepsize = system_get_free_heap_size(); uint32 rtctime = system_get_rtc_time(); uint32 systime = system_get_time(); os_printf("\n\nSDK version: [%s]\n", system_get_sdk_version()); os_printf("SYSTEM INIT OVER\n"); os_printf("==========SYS INFO==========\n"); system_print_meminfo(); os_printf("CHIP ID: [%d]\n", chipid); os_printf("HEAP SIZE: [%d]\n", heepsize); os_printf("RTC TIME: [%d]\n", rtctime); os_printf("SYS TIME: [%d]\n", systime); os_printf("==========SYS INFO==========\n"); }
bool ICACHE_FLASH_ATTR hap_init() { settings_load(); httpd_register(index_httpd_request); static ETSTimer upTimeTimer; os_timer_disarm(&upTimeTimer); os_timer_setfn(&upTimeTimer, (os_timer_func_t *)uptimeIncrement, NULL); os_timer_arm(&upTimeTimer, 1000, 1); wifi_set_event_handler_cb(onWifiEvent); bool result; if (!settings_valid()) { DEBUG_PRINT("[HAP]Settings not valid, using defaults, starting AP\n"); settings.password[0] = 0; settings.ssid[0] = 0; strcpy(settings.serverName, "hap_server"); strcpy(settings.mqttUser, "user"); strcpy(settings.mqttPassword, "password"); strcpy(settings.mqttTopic, "topic"); settings.udpPort = 5100; char aux[20]; os_sprintf(aux, "hap_%d", system_get_chip_id()); result = setup_wifi_ap_mode(aux); } else { DEBUG_PRINT("[HAP]Settings valid, connecting to AP %s\n", settings.ssid); udp_init(); result = setup_wifi_st_mode(settings.ssid, settings.password); } if (result) httpd_init(80); return result; }
void ICACHE_FLASH_ATTR CFG_Load() { INFO("load from 0x%X ...",CFG_LOCATION * SPI_FLASH_SEC_SIZE); spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE, (uint32 *)&saveFlag, sizeof(SAVE_FLAG)); if (saveFlag.flag == 0) { spi_flash_read((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE, (uint32 *)&sysCfg, sizeof(SYSCFG)); } else { spi_flash_read((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE, (uint32 *)&sysCfg, sizeof(SYSCFG)); } if(sysCfg.cfg_holder != CFG_HOLDER){ os_memset(&sysCfg, 0x00, sizeof sysCfg); INFO(" SSID : %s, PASS : %s ",STA_SSID,STA_PASS); sysCfg.cfg_holder = CFG_HOLDER; os_sprintf(sysCfg.sta_ssid, "%s", STA_SSID); os_sprintf(sysCfg.sta_pwd, "%s", STA_PASS); sysCfg.sta_type = STA_TYPE; os_sprintf(sysCfg.device_id, MQTT_CLIENT_ID, system_get_chip_id()); os_sprintf(sysCfg.mqtt_host, "%s", MQTT_HOST); sysCfg.mqtt_port = MQTT_PORT; os_sprintf(sysCfg.mqtt_user, "%s", MQTT_USER); os_sprintf(sysCfg.mqtt_pass, "%s", MQTT_PASS); sysCfg.security = DEFAULT_SECURITY; /* default non ssl */ sysCfg.mqtt_keepalive = MQTT_KEEPALIVE; INFO("default configuration"); CFG_Save();// LMR commented out } }