void user_init(void)
{
	// Configure the UART
	uart_init(BIT_RATE_115200,0);
	// Enable system messages
	system_set_os_print(1);
	os_printf("\r\nSDK version: %s\n", system_get_sdk_version());
	os_printf("System init...\r\n");

	os_printf("ESP8266 is %s mode, restarting in %s mode...\r\n", WiFiMode[wifi_get_opmode()], WiFiMode[STATION_MODE]);
	setup_wifi_st_mode();
	if(wifi_get_phy_mode() != PHY_MODE_11N)
		wifi_set_phy_mode(PHY_MODE_11N);
	if(wifi_station_get_auto_connect() == 0)
		wifi_station_set_auto_connect(1);

	// Init DHT22 sensor
	DHTInit(DHT22);

	// Wait for Wi-Fi connection
	os_timer_disarm(&WiFiLinker);
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, 1000, 0);

	// Set up a timer to send the message
	os_timer_disarm(&dht22_timer);
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DATA_SEND_DELAY, 1);

	os_printf("System init done.\n");
}
Example #2
0
LOCAL void ICACHE_FLASH_ATTR initDone_cb() {
	CFG_Load();
	os_printf("\n%s starting ...\n", sysCfg.deviceName);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.security);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass,
			sysCfg.mqtt_keepalive, 1);

	char temp[100];
	os_sprintf(temp, "/Raw/%s/offline", sysCfg.device_id);
	MQTT_InitLWT(&mqttClient, temp, "offline", 0, 0);

	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	os_printf("SDK version is: %s\n", system_get_sdk_version());
	os_printf("Smart-Config version is: %s\n", smartconfig_get_version());
	system_print_meminfo();
	os_printf("Flash size map %d; id %lx\n", system_get_flash_size_map(), spi_flash_get_id());

	WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, sysCfg.deviceName, wifiConnectCb);

	lcdInit();
	lightOn();
	showString(1, 1, "MQTT Monitor");
}
Example #3
0
void user_init(void) {
    uart_div_modify(0, UART_CLK_FREQ / 115200);
    os_delay_us(500);
    printf("SDK version : %s\n", system_get_sdk_version());
    mainqueue = xQueueCreate(10, sizeof(my_event_t));

    connectToAp();
    //setap("test", 4);

    init_led();

    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5);
    PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO5_U); // disable pullodwn
    GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS,BIT5);
    GPIO_OUTPUT_SET(GPIO_ID_PIN(5), 1);

    char outbuffer[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    WS2812OutBuffer( outbuffer, 6 , 0); //Initialize the output.
    write_textwall_buffer(0, "BIER ", 5);


    xTaskCreate(simple_task, (signed char * )"simple_task", 256, &mainqueue, tskIDLE_PRIORITY, NULL);
    xTaskCreate(receive_udp, (signed char * )"test", 256, &mainqueue, tskIDLE_PRIORITY, NULL);

    timerHandle = xTimerCreate((signed char *) "Trigger", 50 / portTICK_RATE_MS, pdTRUE, NULL, timer_cb);
    if (timerHandle != NULL) {
        if (xTimerStart(timerHandle, 0) != pdPASS) {
            printf("%s: Unable to start Timer ...\n", __FUNCTION__);
        }
    } else {
        printf("%s: Unable to create Timer ...\n", __FUNCTION__);
    }
}
Example #4
0
void user_init(void) {
  uart_init(BIT_RATE_115200, BIT_RATE_115200);

  os_printf("SDK Version: %s\r\n", system_get_sdk_version());

  DHTInit(SENSOR_DHT22, 10000);
}
Example #5
0
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());
	
    wifi_set_opmode(STATION_MODE);
    smartconfig_start(smartconfig_done);
}
Example #6
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
	uart_div_modify(0, UART_CLK_FREQ / 115200);
	
    os_printf("SDK version:%s\n", system_get_sdk_version());
	
	uint32 num = 0;

#if ESP_PLATFORM
    /*Initialization of the peripheral drivers*/
    /*For light demo , it is user_light_init();*/
    /* Also check whether assigned ip addr by the router.If so, connect to ESP-server  */
    //user_esp_platform_init();
#endif
    /*Establish a udp socket to receive local device detect info.*/
    /*Listen to the port 1025, as well as udp broadcast.
    /*If receive a string of device_find_request, it rely its IP address and MAC.*/
    //user_devicefind_init();

    /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
    /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
    /*the JSON command for curl is like:*/
    /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light      */
    /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light      */
	user_light_init();
	
    user_webserver_init(SERVER_PORT);

	pwm_set_duty(10000, 0);
	
	pwm_start();

	
}
Example #7
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    partition_item_t partition_item;
    os_printf("SDK version:%s\n", system_get_sdk_version());

    if (!system_partition_get_item(SYSTEM_PARTITION_CUSTOMER_PRIV_PARAM, &partition_item)) {
        os_printf("Get partition information fail\n");
    }
    priv_param_start_sec = partition_item.addr/SPI_FLASH_SEC_SIZE;
#if ESP_PLATFORM
    /*Initialization of the peripheral drivers*/
    /*For light demo , it is user_light_init();*/
    /* Also check whether assigned ip addr by the router.If so, connect to ESP-server  */
    user_esp_platform_init();
#endif
    /*Establish a udp socket to receive local device detect info.*/
    /*Listen to the port 1025, as well as udp broadcast.
    /*If receive a string of device_find_request, it rely its IP address and MAC.*/
    // user_devicefind_init();

    /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
    /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
    /*the JSON command for curl is like:*/
    /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light      */
    /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light      */
#ifdef SERVER_SSL_ENABLE
    //user_webserver_init(SERVER_SSL_PORT);
#else
    //user_webserver_init(SERVER_PORT);
#endif

    schedule_create(0);
}
void ICACHE_FLASH_ATTR user_init(void) {
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	os_printf("SDK version:%s\n", system_get_sdk_version());
	i2c_init();
#ifdef ESP8266OLED
	oled_init();
#endif
	key_and_gpio_init();
#ifdef ESP8266DOOR
	door_switch_init();
#endif
	wifi_set_event_handler_cb(wifi_handle_event_cb);
	mqttstart();
#ifdef ESP8266ENVINFO
	task_send_environment_info_init();
#endif
#ifdef ESP8266CARDREAD
	pn532_init();
	pn532_cb_event_init();
#endif
	struct station_config s_staconf;
	wifi_station_get_config_default(&s_staconf);
	if (os_strlen(s_staconf.ssid) == 0) {
		wifi_set_opmode(STATION_MODE);
		smartconfig_set_type(SC_TYPE_ESPTOUCH);
		smartconfig_start(smartconfig_done);
	}
}
Example #9
0
/**
 * @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();
}
Example #10
0
void user_init()
{
    struct station_config conf;

    // This is used to setup the serial communication
    uart_div_modify(0, UART_CLK_FREQ / 115200);

    wifi_set_opmode(STATION_MODE);

    // os_bzero ( &conf, sizeof(struct station_config) );
    os_memset ( &conf, 0, sizeof(struct station_config) );
    os_memcpy (&conf.ssid, ssid, 32);
    os_memcpy (&conf.password, pass, 64 );
    wifi_station_set_config (&conf);

    // And this is used to print some information
    os_printf("\n");
    os_printf("SDK version:%s\n", system_get_sdk_version());
    system_print_meminfo();
    os_delay_us ( 1 );
    os_printf ( "CPU Hz = %d\n", system_get_cpu_freq() );

    show_mac ();
    show_ip ();

    /* set a callback for wifi events */
    wifi_set_event_handler_cb ( wifi_event );
}
Example #11
0
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
//    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    os_printf("Blinky, SDK version:%s\n", system_get_sdk_version());
    gdb_stub_init();

    // Initialize the GPIO subsystem.
    gpio_init();

    //Set GPIO2 to output mode
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

    //Set GPIO2 low
    gpio_output_set(0, BIT2, BIT2, 0);

    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 1000, 1);

    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    gdb_breakpoint();
}
Example #12
0
STATIC mp_obj_t os_uname(void) {
    if (os_uname_info_obj.items[2] == NULL) {
        const char *ver = system_get_sdk_version();
        os_uname_info_obj.items[2] = mp_obj_new_str(ver, strlen(ver), false);
    }
    return (mp_obj_t)&os_uname_info_obj;
}
Example #13
0
static void
print_stuff() {
	printf("tmr now = %ss\n", time_now_f());

	printf("SDK version: %s\n", system_get_sdk_version());
	printf("APP version: %s built: %s %s\n", BUILD_DATE, __DATE__, __TIME__);

	printf("CPU freq was %d\n", system_get_cpu_freq());
	printf("CPU freq = %d\n", set_cpu_freq(160));
	printf("tmr now = %ss\n", time_now_f());

	printf("tout    = %sV\n", ffp(3, read_tout(0)*123/10));
	printf("vdd     = %sV\n", ffp(3, read_vdd()));

	print_mac(STATION_IF);
	print_mac(SOFTAP_IF);

	print_ip_info(SOFTAP_IF);
	print_ip_info(STATION_IF);

	printf("tmr now = %ss\n", time_now_f());
	printf("sleeping 2s\n");
	system_deep_sleep(2*1000000);
	vTaskDelete(NULL);
}
Example #14
0
extern "C" void  __attribute__((weak)) user_init(void)
{
    printf("Sming RTOS Proof of Concept \r\n");
    printf("SDK version:%s\n", system_get_sdk_version());
    printf("FreeHeapSize = %d\r\n",xPortGetFreeHeapSize());
    init();
}
Example #15
0
enum mgos_init_result esp_mgos_init2(void) {
#ifdef CS_MMAP
  mgos_vfs_mmap_init();
#endif
  enum mgos_init_result ir = mgos_debug_uart_init();
  if (ir != MGOS_INIT_OK) return ir;
  uart_initialized = true;
  cs_log_set_level(MGOS_EARLY_DEBUG_LEVEL);
  setvbuf(stdout, NULL, _IOLBF, 256);
  setvbuf(stderr, NULL, _IOLBF, 256);
  /* Note: putc can be invoked from int handlers. */
  os_install_putc1(sdk_putc);
  fputc('\n', stderr);

  if (strcmp(MGOS_APP, "mongoose-os") != 0) {
    LOG(LL_INFO, ("%s %s (%s)", MGOS_APP, build_version, build_id));
  }
  LOG(LL_INFO, ("Mongoose OS %s (%s)", mg_build_version, mg_build_id));
  LOG(LL_INFO, ("CPU: %s, %d MHz, RAM: %u total, %u free",
                esp_chip_type_str(esp_get_chip_type()),
                (int) (mgos_get_cpu_freq() / 1000000), mgos_get_heap_size(),
                mgos_get_free_heap_size()));
  LOG(LL_INFO, ("SDK %s; flash: %uM", system_get_sdk_version(),
                esp_vfs_dev_sysflash_get_size(NULL) / 1048576));
  esp_print_reset_info();

  system_soft_wdt_stop();
  ir = mgos_init();
  if (ir != MGOS_INIT_OK) {
    LOG(LL_ERROR, ("%s init error: %d", "MG", ir));
    return ir;
  }

  return MGOS_INIT_OK;
}
Example #16
0
void sysinfo(void)
{
    os_printf("SDK version: %s Chip ID=%u\n",
        system_get_sdk_version(),
        system_get_chip_id());
    system_print_meminfo();
    meminfo();
}
Example #17
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    printf("SDK version:%s\n", system_get_sdk_version());

	uart_init_new();

	xTaskCreate(my_task, "my_task", 128, NULL, 4, NULL);
}
Example #18
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)));
}
Example #19
0
void ICACHE_FLASH_ATTR
user_init(void)
{
	uart_init(BIT_RATE_19200, BIT_RATE_19200);
	os_printf("SDK version:%s\n", system_get_sdk_version());
	wifi_set_opmode(STATION_MODE);
	system_init_done_cb(bridge_init);
}
Example #20
0
void
print_sysinfo(void)
{
    os_printf("\x0c");
    os_printf("*** Welcome to DS18B20 Temperature Reader ***\n");
    os_printf("SDK Version: %s\n", system_get_sdk_version());
    system_print_meminfo();
}
Example #21
0
//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);
}
Example #22
0
/*JSON{
  "type"     : "staticmethod",
  "class"    : "ESP8266WiFi",
  "name"     : "getState",
  "generate" : "jswrap_ESP8266WiFi_getState",
  "return"   : ["JsVar","The state of the ESP8266"],
  "return_object" : "ESP8266State"
}*/
JsVar *jswrap_ESP8266WiFi_getState() {
  // Create a new variable and populate it with the properties of the ESP8266 that we
  // wish to return.
  JsVar *esp8266State = jspNewObject(NULL, "ESP8266State");
  jsvUnLock(jsvObjectSetChild(esp8266State, "sdkVersion",   jsvNewFromString(system_get_sdk_version())));
  jsvUnLock(jsvObjectSetChild(esp8266State, "cpuFrequency", jsvNewFromInteger(system_get_cpu_freq())));
  jsvUnLock(jsvObjectSetChild(esp8266State, "freeHeap",     jsvNewFromInteger(system_get_free_heap_size())));
  jsvUnLock(jsvObjectSetChild(esp8266State, "maxCon",       jsvNewFromInteger(espconn_tcp_get_max_con())));
  return esp8266State;
}
Example #23
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
    printf("SDK version:%s\n", system_get_sdk_version());

    /* need to set opmode before you set config */
    wifi_set_opmode(STATION_MODE);

    xTaskCreate(smartconfig_task, "smartconfig_task", 256, NULL, 2, NULL);
}
Example #24
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());
   
    //Set station mode 
    wifi_set_opmode(STATION_MODE); 

    //ESP8266 connect to router
    user_set_station_config();
}
Example #25
0
/**
  * @brief  Execution commad of version.
  * @param  id: commad id number
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_exeCmdGmr(uint8_t id)
{
  char temp[64];

  os_sprintf(temp, AT_VERSION);
  uart0_sendStr(temp);
  os_sprintf(temp,"%s\r\n", system_get_sdk_version());
  uart0_sendStr(temp);
  at_backOk;
}
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("");
}
Example #27
0
void ICACHE_FLASH_ATTR user_init(void)
{  
    uart_div_modify(0, UART_CLK_FREQ / 115200);
    gpio_user_init();

    printf("SDK version:%s\n", system_get_sdk_version());

    //init_blinking_led();

    network_init();
}
Example #28
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
#if DEBUG_MODE
    os_printf(" \n");
#endif

#if DEBUG_MODE
    os_printf("SDK version is :%s\n", system_get_sdk_version());
#endif


}
Example #29
0
void user_init(void)
{
	uart_init(115200, 115200);

	//Set softap + station mode
	wifi_set_opmode(STATIONAP_MODE);

	os_printf("SDK version:%s\r\n", system_get_sdk_version());

	// Create udp listening.
	user_udp_init();
}
Example #30
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
	load_userParam();
	uart_init(myParam.baud_rate, myParam.baud_rate);
    os_printf("SDK version:%s\n", system_get_sdk_version());
	uart0_sendStr("\r\nready\r\n");  
	user_wifi_init();
	user_socket_init(myParam.port);
	user_web_init();
	
	
}