Пример #1
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void) {
	sys_read_cfg();
	if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0);
	uart_init();
#if USE_TMP2NET_PORT
	GPIO0_MUX = 0;
#else
	GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF;
#endif
	GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF;
	GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF;
	GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF;
	GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF;
	system_timer_reinit();
#if DEBUGSOO > 0
	os_printf("\nSimple WEB version: " WEB_SVERSION "\nOpenLoaderSDK v1.2\n");
#endif
	if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config();
	set_cpu_clk(); // select cpu frequency 80 or 160 MHz
#if DEBUGSOO > 0
	if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base,  eraminfo.size);
	os_printf("System memory:\n");
    system_print_meminfo();
    os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size());
#endif
#if DEBUGSOO > 0
	os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency());
#endif
	Setup_WiFi();
#if USE_TMP2NET_PORT
	tpm2net_init();
#endif
#ifdef USE_NETBIOS
	if(syscfg.cfg.b.netbios_ena) netbios_init();
#endif
/* #ifdef USE_SNTP
	if(syscfg.cfg.b.sntp_ena) sntp_init();
#endif */
#ifdef UDP_TEST_PORT
	if(syscfg.udp_port) udp_test_port_init(syscfg.udp_port);
#endif
	// инициализация и запуск tcp серверa(ов)
#ifdef USE_SRV_WEB_PORT
    if(syscfg.web_port) webserver_init(syscfg.web_port);
#endif
///    if(syscfg.tcp2uart_port) tcp2uart_init(syscfg.tcp2uart_port);
#ifdef USE_MODBUS
    mdb_tcp_init(502);
#endif
#ifdef USE_WDRV
    init_wdrv();
#endif
	system_deep_sleep_set_option(0);
	system_init_done_cb(init_done_cb);
}
Пример #2
0
// Main routine to initialize esp-link.
void user_init(void) {
  // get the flash config so we know how to init things
  //configWipe(); // uncomment to reset the config for testing purposes
  bool restoreOk = configRestore();
  // Init gpio pin registers
  gpio_init();
  gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
  // init UART
  uart_init(flashConfig.baud_rate, 115200);
  logInit(); // must come after init of uart
  // Say hello (leave some time to cause break in TX after boot loader's msg
  os_delay_us(10000L);
  os_printf("\n\n** %s\n", esp_link_version);
  os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*");
  // Status LEDs
  statusInit();
  serledInit();
  // Wifi
  wifiInit();
  // init the flash filesystem with the html stuff
  espFsInit(&_binary_espfs_img_start);
  //EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
  //os_printf("espFsInit %s\n", res?"ERR":"ok");
  // mount the http handlers
  httpdInit(builtInUrls, 80);
  // init the wifi-serial transparent bridge (port 23)
  serbridgeInit(23, 2323);
  uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
  os_timer_disarm(&prHeapTimer);
  os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
  os_timer_arm(&prHeapTimer, 10000, 1);
#endif

  struct rst_info *rst_info = system_get_rst_info();
  NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]);
  NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x",
    rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
    rst_info->excvaddr, rst_info->depc);
  uint32_t fid = spi_flash_get_id();
  NOTICE("Flash map %s, manuf 0x%02X chip 0x%04X", flash_maps[system_get_flash_size_map()],
      fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
  NOTICE("** %s: ready, heap=%ld", esp_link_version, (unsigned long)system_get_free_heap_size());

  // Init SNTP service
  cgiServicesSNTPInit();
#ifdef MQTT
  NOTICE("initializing MQTT");
  mqtt_client_init();
#endif
  NOTICE("initializing user application");
  app_init();
  NOTICE("Waiting for work to do...");
}
Пример #3
0
int ICACHE_FLASH_ATTR
mqttStatusMsg(char *buf) {
  sint8 rssi = wifi_station_get_rssi();
  if (rssi > 0) rssi = 0; // not connected or other error
  //os_printf("timer rssi=%d\n", rssi);

  // compose MQTT message
  return os_sprintf(buf,
    "{\"rssi\":%d, \"heap_free\":%ld}",
    rssi, (unsigned long)system_get_free_heap_size());
}
Пример #4
0
/******************************************************************************
 * FunctionName : espconn_server_recv
 * Description  : Data has been received on this pcb.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb which received data
 *                p -- The received data (or NULL when the connection has been closed!)
 *                err -- An error code if there has been an error receiving
 * Returns      : ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
	espconn_msg *precv_cb = arg;

    tcp_arg(pcb, arg);
    espconn_printf("server has application data received: %d\n", system_get_free_heap_size());
    if (p != NULL) {
        tcp_recved(pcb, p->tot_len);
    }

    if (err == ERR_OK && p != NULL) {
    	u8_t *data_ptr = NULL;
    	u32_t data_cntr = 0;
		precv_cb->pcommon.recv_check = 0;
        data_ptr = (u8_t *)os_zalloc(p ->tot_len + 1);
        data_cntr = pbuf_copy_partial(p, data_ptr, p ->tot_len, 0);
        pbuf_free(p);

        if (data_cntr != 0) {
        	precv_cb->pespconn ->state = ESPCONN_READ;
        	precv_cb->pcommon.pcb = pcb;
            if (precv_cb->pespconn->recv_callback != NULL) {
            	precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);
            }
            precv_cb->pespconn ->state = ESPCONN_CONNECT;
        }

        os_free(data_ptr);
        data_ptr = NULL;
        espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
    } else {
        if (p != NULL) {
            pbuf_free(p);
        }

        espconn_server_close(precv_cb, pcb);
    }

    return ERR_OK;
}
Пример #5
0
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");
}
Пример #6
0
//Retires a connection for re-use
static void ICACHE_FLASH_ATTR httpdRetireConn(HttpdConnData *conn) {
	uint32 dt = conn->startTime;
	if (dt > 0) dt = (system_get_time() - dt)/1000;
	os_printf("%s Closed, took %ums, heap=%ld\n", connStr, dt,
			(unsigned long)system_get_free_heap_size());
	if (conn->post->buff!=NULL) os_free(conn->post->buff);
	conn->post->buff=NULL;
	conn->cgi=NULL;
	conn->conn=NULL;
	conn->remote_port = 0;
	conn->remote_ip[0] = 0;
}
Пример #7
0
time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
  int n = 0;
  time_t now = time(NULL);
  struct mg_connection *nc, *tmp;
  (void) timeout_ms;
  DBG(("begin poll, now=%u, hf=%u, sf lwm=%u", (unsigned int) now,
       system_get_free_heap_size(), 0U));
  for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
    struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
    (void) cs;
    tmp = nc->next;
    n++;
    if (nc->flags & MG_F_CLOSE_IMMEDIATELY) {
      mg_close_conn(nc);
      continue;
    }
    mg_if_poll(nc, now);
    mg_if_timer(nc, now);
    if (nc->send_mbuf.len == 0 && (nc->flags & MG_F_SEND_AND_CLOSE) &&
        !(nc->flags & MG_F_WANT_WRITE)) {
      mg_close_conn(nc);
      continue;
    }
#ifdef SSL_KRYPTON
    if (nc->ssl != NULL && cs != NULL && cs->pcb.tcp != NULL &&
        cs->pcb.tcp->state == ESTABLISHED) {
      if (((nc->flags & MG_F_WANT_WRITE) || nc->send_mbuf.len > 0) &&
          cs->pcb.tcp->snd_buf > 0) {
        /* Can write more. */
        if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
          if (!(nc->flags & MG_F_CONNECTING)) mg_lwip_ssl_send(nc);
        } else {
          mg_lwip_ssl_do_hs(nc);
        }
      }
      if (cs->rx_chain != NULL) {
        if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
          if (!(nc->flags & MG_F_CONNECTING)) mg_lwip_ssl_recv(nc);
        } else {
          mg_lwip_ssl_do_hs(nc);
        }
      }
    } else
#endif /* SSL_KRYPTON */
    {
      if (!(nc->flags & (MG_F_CONNECTING | MG_F_UDP))) {
        if (nc->send_mbuf.len > 0) mg_lwip_send_more(nc);
      }
    }
  }
  DBG(("end poll, %d conns", n));
  return now;
}
Пример #8
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void) {
	if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base,  eraminfo.size);
	os_printf("System memory:\n");
    system_print_meminfo();
    os_printf("bssi  : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start));
    os_printf("free  : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end));
    os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size());
	os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency());
	system_deep_sleep_set_option(0);
	wifi_set_event_handler_cb(wifi_handle_event_cb);
	system_init_done_cb(init_done_cb);
}
Пример #9
0
EXP_FUNC void * ICACHE_FLASH_ATTR ax_zalloc(size_t s, const char* file, int line)
{
    void *x;

    if ((x = (void*)zalloc(s)) == NULL)
    	exit_now("out of memory %s %d\n", file, line);
    else {
    	debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size());
		//add_mem_info(x, s, file, line);
    	}

    return x;
}
Пример #10
0
dce_result_t SECTION_ATTR dce_handle_GMEM(dce_t* dce, void* group_ctx, int kind, size_t argc, arg_t* argv)
{
    char line[12];
    int length = sprintf(line, "%d", system_get_free_heap_size());
    dce_emit_information_response(dce, line, length);

    int debug_enabled = uart_get_debug();
    uart_set_debug(1);
    system_print_meminfo();
    uart_set_debug(debug_enabled);
    
    dce_emit_basic_result_code(dce, DCE_RC_OK);
}
/******************************************************************************
 * FunctionName : mesh_EnableCb
 * Description  : callback func for espconn_mesh_enable
                  enable callback will only be called if the device has already joined a mesh network
*******************************************************************************/
void ICACHE_FLASH_ATTR
mesh_EnableCb()
{
    mesh_StopCheckTimer();
    _LINE_DESP();
    MESH_INFO("TEST IN MESH ENABLE CB\r\n");
    MESH_INFO("%s\n", __func__);
    MESH_INFO("HEAP: %d \r\n",system_get_free_heap_size());
    _LINE_DESP();
    if(LightMeshProc.mesh_suc_cb){
        LightMeshProc.mesh_suc_cb(NULL);
    }
}
Пример #12
0
EXP_FUNC void * ICACHE_FLASH_ATTR ax_calloc(size_t n, size_t s, const char* file, int line)
{
    void *x;
	//unsigned total_size =0;
    if ((x = calloc(n, s)) == NULL)
    	exit_now("out of memory %s %d\n", file, line);
    else {
    	debug_now("%s %d point[%p] size[%d] heap[%d]\n", file, line, x, s, system_get_free_heap_size());
		//total_size = n * s;		 
		//add_mem_info (x, total_size, file, line);
    	}

    return x;
}
Пример #13
0
void ICACHE_FLASH_ATTR dhsender_queue_init() {
	mQueueMaxSize = (system_get_free_heap_size() - MEMORY_RESERVER) / sizeof(DHSENDER_QUEUE);
	if(mQueueMaxSize > MAX_QUEUE_LENGTH)
		mQueueMaxSize = MAX_QUEUE_LENGTH;
	mQueue = (DHSENDER_QUEUE *)os_malloc(mQueueMaxSize * sizeof(DHSENDER_QUEUE));
	if(mQueue == 0) {
		dhdebug("ERROR: can not allocate memory for queue");
	} else {
		if(mQueueMaxSize < 10)
			dhdebug("Warning: queue is very shot - %u", mQueueMaxSize);
		else
			dhdebug("Queue created, size %u", mQueueMaxSize);
	}
}
Пример #14
0
static void ICACHE_FLASH_ATTR
MQTT_exit(MQTT_Client *client)
{
	if(client == NULL)
	{
		return;
	}
	if(client->host != NULL)
	{
		os_free(client->host);
		client->host = NULL;
	}
	if(client->connect_info.password != NULL)
	{
		os_free(client->connect_info.password);
		client->connect_info.password = NULL;
	}
	if(client->connect_info.client_id != NULL)
	{
		os_free(client->connect_info.client_id);
		client->connect_info.client_id = NULL;
	}
	if(client->connect_info.username != NULL)
	{
		os_free(client->connect_info.username);
		client->connect_info.username = NULL;
	}
	if(client->mqtt_state.in_buffer != NULL)
	{
		os_free(client->mqtt_state.in_buffer);
		client->mqtt_state.in_buffer = NULL;
	}
	if(client->mqtt_state.out_buffer != NULL)
	{
		os_free(client->mqtt_state.out_buffer);
		client->mqtt_state.out_buffer = NULL;
	}
	if(client->msgQueue.buf != NULL)
	{
		os_free(client->msgQueue.buf);
		client->msgQueue.buf = NULL;
	}
	INFO("mqtt exit:\n");
	INFO("available heap size:%d\n", system_get_free_heap_size());
	if(client->errorCb != NULL)
	{
		(client->errorCb)((uint32_t*)client);
	}
}
Пример #15
0
void ICACHE_FLASH_ATTR init_done_cb(void)
{
    os_printf("\nSDK Init - Ok\nCurrent 'heap' size: %d bytes\n", system_get_free_heap_size());
#ifdef USE_WEB
	web_fini(inifname);
#endif
	switch(system_get_rst_info()->reason) {
	case REASON_SOFT_RESTART:
	case REASON_DEEP_SLEEP_AWAKE:
		break;
	default:
		New_WiFi_config(WIFI_MASK_ALL);
		break;
	}
}
Пример #16
0
////////////////////
// make html footer
////////////////////
String MakeHTTPFooter()
{
  String sResponse;

  sResponse  = F("<FONT SIZE=-2><BR>Aufrufz&auml;hler=");
  sResponse += ulReqcount;
  sResponse += F(" - Verbindungsz&auml;hler=");
  sResponse += ulReconncount;
  sResponse += F(" - Freies RAM=");
  sResponse += (uint32_t)system_get_free_heap_size();
  sResponse += F(" - Max. Datenpunkte=");
  sResponse += ulNoMeasValues;
  sResponse += F("<BR>SMASE 03/2016 | Tobias Winter -> Mail: [email protected] <BR></body></html>");

  return (sResponse);
}
Пример #17
0
/* ======================================================================
Function: getSpiffsJSONData 
Purpose : Return JSON string containing list of SPIFFS files
Input   : Response String
Output  : - 
Comments: -
====================================================================== */
void getSpiffsJSONData(String & response)
{
  char buffer[32];
  bool first_item = true;

  // Json start
  response = FPSTR(FP_JSON_START);

  // Files Array  
  response += F("\"files\":[\r\n");

  // Loop trough all files
  Dir dir = SPIFFS.openDir("/");
  while (dir.next()) {    
    String fileName = dir.fileName();
    size_t fileSize = dir.fileSize();
    if (first_item)  
      first_item=false;
    else
      response += ",";

    response += F("{\"na\":\"");
    response += fileName.c_str();
    response += F("\",\"va\":\"");
    response += fileSize;
    response += F("\"}\r\n");
  }
  response += F("],\r\n");


  // SPIFFS File system array
  response += F("\"spiffs\":[\r\n{");
  
  // Get SPIFFS File system informations
  FSInfo info;
  SPIFFS.info(info);
  response += F("\"Total\":");
  response += info.totalBytes ;
  response += F(", \"Used\":");
  response += info.usedBytes ;
  response += F(", \"ram\":");
  response += system_get_free_heap_size() ;
  response += F("}\r\n]"); 

  // Json end
  response += FPSTR(FP_JSON_END);
}
Пример #18
0
Файл: sample.c Проект: hwwr/test
int ICACHE_FLASH_ATTR alink_get_debuginfo(info_type type, char *status)
{
	int used;
	switch (type) {
	case MEMUSED:
		used = 100 - ((system_get_free_heap_size() * 100) / (96 * 1024));
		sprintf(status, "%d%%", used);
		break;
	case WIFISTRENGTH:
		sprintf(status, "%ddB", wifi_station_get_rssi());
		break;
	default:
		status[0] = '\0';
		break;
	}
	return 0;
}
Пример #19
0
void ICACHE_FLASH_ATTR user_uart_task(void *pvParameters)
{
	CusUartIntrPtr uartptrData;
	u32 sys_time_value = system_get_time();

	while (1)
	{
		
		if (EmptyQueue() == false && (system_get_time() - sys_time_value) >= 100) {

			ESP_DBG(("***heap_size %d\n", system_get_free_heap_size()));

			frame_t frame;

			if (Dequeue(&frame)) {
				uart0_tx_buffer((uint8_t *)&frame, frame.len);
			}
			sys_time_value = system_get_time();
		}
		
		if (xQueueReceive(xQueueCusUart, (void *)&uartptrData, (portTickType)20/*portMAX_DELAY*/)) // wait about 20msec 
		{
			ESP_DBG(("data uart recv.."));
			debug_print_hex_data(uartptrData.rx_buf, uartptrData.rx_len);

			if (uartptrData.rx_len>0x00) {
				cus_uart_data_handle(uartptrData.rx_buf, uartptrData.rx_len, NULL);
			}
		}
		/*
		if ((system_get_time() - sys_time_value) >= (60 * 1000 * 1000))  //about 1min, send data to uart0, demo beat data
		{
			ESP_DBG(("uart beat data***heap_size %d\n", system_get_free_heap_size()));
			
			//uart0_write_data(uart_beat_data, sizeof(uart_beat_data));//heatbeat sent to MCU
			
			sys_time_value = system_get_time();
		}
		*/
		
	}

	vTaskDelete(NULL);

}
Пример #20
0
// 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;
  }
}
Пример #21
0
/**
 * Perform the main loop processing.
 * This is where work is performed
 * as often as possible.
 */
static void mainLoop() {
  if (suspendMainLoopFlag == true) {
    return;
  }
  jsiLoop();

#ifdef EPS8266_BOARD_HEARTBEAT
  if (system_get_time() - lastTime > 1000 * 1000 * 5) {
    lastTime = system_get_time();
    os_printf("tick: %u, heap: %u\n",
      (uint32)(jshGetSystemTime()), system_get_free_heap_size());
  }
#endif

  // Setup for another callback
  //queueTaskMainLoop();
  suspendMainLoop(0); // HACK to get around SDK 1.4 bug
}
Пример #22
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");
}
Пример #23
0
//Template code for the counter on the index page.
void ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) {
	char buff[128];
	if (token==NULL) return;

	if (os_strcmp(token, "counter")==0) {
		hitCounter++;
		os_sprintf(buff, "%ld", hitCounter);
	}

	if (os_strcmp(token, "freeheap")==0) {
		os_sprintf(buff,"Free heap size:%d\n",system_get_free_heap_size());
  	}

	if (os_strcmp(token, "fwver")==0) {
		os_sprintf(buff,"%s",FWVER);
  	}

	httpdSend(connData, buff, -1);
}
Пример #24
0
void wsConnected(WebSocket& socket) {
	totalActiveSockets++;
	lastPositionMessage = "";
	// Notify everybody about new connection

	uint8 slotNo = rboot_get_current_rom();
	String slotNoStr = String(slotNo);

	uint32 heapSize = system_get_free_heap_size();
	String heapSizeStr = String(heapSize);

	WebSocketsList &clients = server.getActiveWebSockets();
	for (int i = 0; i < clients.count(); i++) {
		clients[i].sendString(
				"Connected to station: " + wifi_sid.get(currWifiIndex) + ", ROM:" + slotNoStr + ", heapSize: "
						+ heapSizeStr + ", appVer:1.22, SDK version: " + system_get_sdk_version());
	}

}
Пример #25
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void) {
	sys_read_cfg();
	if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0);
	GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF;
	GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF;
	GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF;
	GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF;
	GPIO13_MUX = VAL_MUX_GPIO13_SDK_DEF;
	GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF;
	GPIO15_MUX = VAL_MUX_GPIO15_SDK_DEF;
	// vad7
	//power_meter_init();
	//
	//uart_init(); // in tcp2uart.h
	system_timer_reinit();
#if (DEBUGSOO > 0 && defined(USE_WEB))
	os_printf("\nSimple WEB version: " WEB_SVERSION "\n");
#endif
	//if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); // сброс настроек, если замкнут пин RX
	set_cpu_clk(); // select cpu frequency 80 or 160 MHz
#ifdef USE_GDBSTUB
extern void gdbstub_init(void);
	gdbstub_init();
#endif
#if DEBUGSOO > 0
	if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base,  eraminfo.size);
	os_printf("System memory:\n");
    system_print_meminfo();
    os_printf("bssi  : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start));
    os_printf("free  : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end));

    os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size());
#endif
#if DEBUGSOO > 0
	os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency());
#endif
	Setup_WiFi();
    WEBFSInit(); // файловая система

	system_deep_sleep_set_option(0);
	system_init_done_cb(init_done_cb);
}
Пример #26
0
void esp_uart_print_status(void *arg) {
  struct esp_uart_state *us = (struct esp_uart_state *) arg;
  struct esp_uart_stats *s = &us->stats;
  struct esp_uart_stats *ps = &us->prev_stats;
  int uart_no = us->cfg->uart_no;
  fprintf(
      stderr,
      "UART%d ints %u/%u/%u; rx en %d bytes %u buf %u fifo %u, ovf %u, lcs %u; "
      "tx %u %u %u, thr %u; hf %u i 0x%03x ie 0x%03x cts %d\n",
      uart_no, s->ints - ps->ints, s->rx_ints - ps->rx_ints,
      s->tx_ints - ps->tx_ints, us->rx_enabled, s->rx_bytes - ps->rx_bytes,
      us->rx_buf.used, rx_fifo_len(us->cfg->uart_no),
      s->rx_overflows - ps->rx_overflows,
      s->rx_linger_conts - ps->rx_linger_conts, s->tx_bytes - ps->tx_bytes,
      us->tx_buf.used, tx_fifo_len(us->cfg->uart_no),
      s->tx_throttles - ps->tx_throttles, system_get_free_heap_size(),
      READ_PERI_REG(UART_INT_RAW(uart_no)),
      READ_PERI_REG(UART_INT_ENA(uart_no)), cts(uart_no));
  memcpy(ps, s, sizeof(*s));
}
Пример #27
0
void ICACHE_FLASH_ATTR user_event_progress(uint8 progress) {
	LOCAL uint8 prev = 0;
	
	uint32 heap = system_get_free_heap_size();
	if (abs(progress - prev) < 3 || heap < 5000) {
		return;
	}
	
	prev = progress;
	char status[WEBSERVER_MAX_VALUE];
	char progress_str[WEBSERVER_MAX_VALUE];
	json_status(status, ESP8266, json_sprintf(progress_str, "Progress: %d\%", progress), NULL);
	
#if EVENTS_DEBUG
	debug("EVENTS: Progress [%d]\n", progress);
#endif
	char event[WEBSERVER_MAX_VALUE + os_strlen(webserver_chunk_url()) + os_strlen(status)];
	
	user_event_build(event, webserver_chunk_url(), status);
	websocket_send_message(EVENTS_URL, event, NULL);
}
Пример #28
0
void mainsetup()
{
  // setup globals
  ulReqcount = 0;
  ulReconncount = 0;
  WiFiStart();
  delay(1);

  server.begin();

  // allocate ram for data storage
  uint32_t free = system_get_free_heap_size() - KEEP_MEM_FREE;
  ulNoMeasValues = free / (sizeof(float) * 5 + sizeof(unsigned long)); // humidity & temp --> 2 + time
  pulTime = new unsigned long[ulNoMeasValues];
  pfTemp1 = new float[ulNoMeasValues];
  pfTemp2 = new float[ulNoMeasValues];
  pfTemp3 = new float[ulNoMeasValues];
  pfTemp4 = new float[ulNoMeasValues];

  if (pulTime == NULL || pfTemp1 == NULL || pfTemp2 == NULL || pfTemp3 == NULL || pfTemp4 == NULL)
  {
    ulNoMeasValues = 0;
    Serial.println("Error in memory allocation!");
  }
  else
  {
    Serial.print("Allocated storage for ");
    Serial.print(ulNoMeasValues);
    Serial.println(" data points.");

    float fMeasDelta_sec = MEAS_SPAN_H * 3600. / ulNoMeasValues;
    ulMeasDelta_ms = ( (unsigned long)(fMeasDelta_sec + 0.5) ) * 1000; // round to full sec
    Serial.print("Measurements will happen each ");
    Serial.print(ulMeasDelta_ms);
    Serial.println(" ms.");

    ulNextMeas_ms = millis() + ulMeasDelta_ms;
  }
}
Пример #29
0
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)));

	Vector<String> files = fileList();
	if (files.count() > 0) {
		Serial.println("\n\rSpiff files:");
		Serial.println("----------------------------");
		{
			for (int i = 0; i < files.count(); i++) {
				Serial.println(files[i]);
			}
		}
		Serial.println("----------------------------");
	} else {
		Serial.println("Empty spiffs!");
	}

}
Пример #30
0
static void disp_task(void *params) {
  struct mg_connection *conn = NULL;
  struct conn_ctx ctx;
  printf("Starting network test...\n");
  memset(data, 'A', sizeof(data));
  memset(&ctx, 0, sizeof(ctx));
  wifi_connect();
  int i = 0;
  while (1) {
    mongoose_poll(2);
    if (!wifi_connected) continue;
    switch (ctx.state) {
      case DISCONNECTED:
        memset(&ctx, 0, sizeof(ctx));
        conn = mg_connect(&sj_mgr, ADDR_TO_CONNECT, conn_handler);
        if (conn == NULL) {
          vTaskDelay(100);
          printf("reconnecting\n");
          continue;
        }
        printf("conn = %p\n", conn);
        conn->user_data = &ctx;
        ctx.state = CONNECTING;
        break;
      case CONNECTING:
        break;
      case CONNECTED:
        i++;
        if (i % 10000 == 0) {
          printf("sent %u, recv %u heap free: %u uptime %d\n", ctx.num_sent,
                 ctx.num_received, system_get_free_heap_size(),
                 system_get_time() / 1000000);
        }
        break;
    }
  }
}