Exemplo n.º 1
0
void user_init(void) {
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
	dnsserver_init();
	os_printf("\nReady\n");
}
Exemplo n.º 2
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
  wifi_station_set_auto_connect(FALSE); 
	stdoutInit();
  CFG_Load();
	ioInit();	     
  
  MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n");	
  stack_init();  

  /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */
  captdnsInit(); 

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
  #ifdef ESPFS_POS
    espFsInit((void*)(0x40200000 + ESPFS_POS));
  #else
    espFsInit((void*)(webpages_espfs_start));
  #endif
  httpdInit(builtInUrls, 80);
  #ifdef SHOW_HEAP_USE
    os_timer_disarm(&prHeapTimer);
    os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
    os_timer_arm(&prHeapTimer, 3000, 1);
  #endif
  os_timer_disarm(&websockTimer);
  os_timer_setfn(&websockTimer, websockTimerCb, NULL);
  os_timer_arm(&websockTimer, 1000, 1);
  
  os_printf("\nReady\n");	
}
Exemplo n.º 3
0
// Main routine, initialize some basic stuff
void ICACHE_FLASH_ATTR user_init(void)
 {
  // Init some stuff
  stdoutInit();
  batteryInit();
  configInit();
  configLoad();

  // Check if wifi mode is correct
  configCheckWifiMode();

  // Measure battery voltage
  batteryMeasureVoltage();
  if(!batteryCheckVoltage())
   {
    // Voltage too low, go to sleep mode!
    sleepmode();
   }

  // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
  // where image is written in flash that is defined in Makefile.
  espFsInit((void*)(0x40200000 + ESPFS_POS));
  httpdInit(builtInUrls, 80);

  // Register callback
  system_init_done_cb(init_done);

  os_printf("Ready\n");
 }
Exemplo n.º 4
0
//Init function 
void ICACHE_FLASH_ATTR user_init() {

    //uart_init(BIT_RATE_115200,BIT_RATE_115200);
    flashData = &_flashData;
    IPStation = ipstation;

    stdoutInit();
    char ssid[32] = SSID;
    char password[64] = SSID_PASSWORD;
    struct station_config stationConf;


    os_printf("\ninit\n");


    user_init_gpio();
    //Set station mode & AP mode
    // wifi_set_opmode(STATION_MODE);
    wifi_set_opmode(STATIONAP_MODE);

    initFlash();
    flash_read();

    //if (flashData->magic != MAGIC_NUM)
    {
    //Set ap settings
        os_memcpy(&stationConf.ssid, ssid, 32);
        os_memcpy(&stationConf.password, password, 64);
    }
//    else
//    {
//        os_memcpy(&stationConf.ssid, flashData->ssid, 32);
//        os_memcpy(&stationConf.password, flashData->password, 64);
//
//    }
    wifi_station_set_config(&stationConf);
    os_printf("\nConnecting to %s, %s\n", stationConf.ssid, stationConf.password);

    SetSetverMode();


    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);

    system_os_post(user_procTaskPrio, 0, 0 );

    os_printf("\nInitializing Network\n");
    network_init(); 


}
Exemplo n.º 5
0
/************************************************
*	name:			user_init
*	parameters:		none
*	return value:	none
*	purpose:		main logic
************************************************/
void user_init(void)
{	
	/* initialization */
	struct softap_config 	tWifiSettings = { 0 };
	uint8 					puMacAddress[6] = { 0 };

	os_memset((void *)&tWifiSettings, 0, sizeof(tWifiSettings));

	wifi_softap_get_config(&tWifiSettings);
	
	/* retrieve mac address */
	wifi_get_macaddr(1, puMacAddress);
	
	/* append to ssid name */
	memcpy(tWifiSettings.ssid, HOTSPOT_SSID_STRING, sizeof(HOTSPOT_SSID_STRING));

	os_sprintf(tWifiSettings.ssid + sizeof(HOTSPOT_SSID_STRING) - 1, "%x%x%x%x%x%x", puMacAddress[0],
							  												  	 	 puMacAddress[1],
							  												  	 	 puMacAddress[2],
							  												  	 	 puMacAddress[3],
							  												  	 	 puMacAddress[4],
							  												  	 	 puMacAddress[5]);
	/* set password */
	memcpy(tWifiSettings.password, HOTSPOT_PASSWORD_STRING, os_strlen(HOTSPOT_PASSWORD_STRING));
	
	/* update other settings */
	tWifiSettings.authmode = AUTH_WPA_WPA2_PSK;
	tWifiSettings.ssid_len = 0;
	tWifiSettings.channel = 6;
	tWifiSettings.max_connection = 4;
	
	/* update wifi configuration */
	wifi_softap_set_config(&tWifiSettings);
	
	/* initialize stdout */
	stdoutInit();
	
	/* initialize IOs */
	ioInit();
	
	/* initialize server */
	httpdInit(g_ptSupportedUrls, 80);
	
#ifdef USER_MAIN_DEBUG
	os_printf("user_init: ready; partition %d\n", system_upgrade_userbin_check());
#endif
}
Exemplo n.º 6
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void user_init(void) {
// HTTPD
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
//MQTT
	uart_init(115200, 115200);
	CFG_Load();
	sleepms(1000);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL);
	//MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1);
	//MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1);

//	MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnPublished(&mqttClient, mqttPublishedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	INFO("device_ID:%s\r\n",sysCfg.device_id);
	INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
//DS18B20 timers
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);

//NTP timers
		ntp_get_time();
		os_timer_disarm(&NTP_timer);
		os_timer_setfn(&NTP_timer, (os_timer_func_t *)ntp_get_time, (void *)0);
		os_timer_arm(&NTP_timer, NTPDELAY, 1);

// initialize GPIO2
	PIN_FUNC_SELECT(PIN_GPIO2_MUX, PIN_GPIO2_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO2, 0);
	INFO("GPIO2 set to OFF\r\n");

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

	os_printf("\nReady\n");
}
Exemplo n.º 7
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
	stdoutInit();
	ioInit();
	captdnsInit();

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
	espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
	espFsInit((void*)(webpages_espfs_start));
#endif
	httpdInit(builtInUrls, 80);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 3000, 1);
#endif
	os_printf("\nReady\n");
}
Exemplo n.º 8
0
//Main routine
void ICACHE_FLASH_ATTR user_init(void) {

	stdoutInit();	
	os_delay_us(100000);
	CFG_Load();
	ioInit();
	
	WIFI_Connect(wifiConnectCb);
	
	httpdInit(builtInUrls, sysCfg.httpd_port);
	
	if(sysCfg.ntp_enable==1) {
		sntp_init(sysCfg.ntp_tz);	//timezone
	}
	
	if(sysCfg.mqtt_enable==1) {
		MQTT_InitConnection(&mqttClient, (uint8_t *)sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_use_ssl );
		MQTT_InitClient(&mqttClient, (uint8_t *)sysCfg.mqtt_devid, (uint8_t *)sysCfg.mqtt_user, (uint8_t *)sysCfg.mqtt_pass, sysCfg.mqtt_keepalive,1);
		MQTT_OnConnected(&mqttClient, mqttConnectedCb);
		MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
		MQTT_OnPublished(&mqttClient, mqttPublishedCb);		
		MQTT_OnData(&mqttClient, mqttDataCb);
		
	}
	
	if(sysCfg.sensor_dht22_enable) 
		DHTInit(SENSOR_DHT22, 30000);
		
	if(sysCfg.sensor_ds18b20_enable) 
		ds_init(30000);

	broadcastd_init();

	thermostat_init(30000);

/*
	//Netbios to set the name
	struct softap_config wiconfig;
	os_memset(netbios_name, ' ', sizeof(netbios_name)-1);
	if(wifi_softap_get_config(&wiconfig)) {
		int i;
		for(i = 0; i < sizeof(netbios_name)-1; i++) {
			if(wiconfig.ssid[i] < ' ') break;
			netbios_name[i] = wiconfig.ssid[i];
		};
	}
	else os_sprintf(netbios_name, "ESP8266");
	netbios_name[sizeof(netbios_name)-1]='\0';
	netbios_init();
*/
		
	os_printf("\nRelay Board Ready\n");	
	os_printf("Free heap size:%d\n",system_get_free_heap_size());

	
#ifdef CGIPWM_H	
	//Mind the PWM pin!! defined in pwm.h
	duty=0;
	pwm_init( 50, &duty);
	pwm_set_duty(duty, 0);
    pwm_start();
#endif
	
	//OLEDInit();
	
}
Exemplo n.º 9
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void user_init(void) {
// my stuff
	dBR_BOILER_SET=65; // default setting 65C boiler temperature on reboot
	dBR_TEMP_ROOM_SET=18; // default setting 18C room temperature on reboot
	dBR_HUMIDITY_SET=60; // default setting 65% humidity target on reboot
	dBR_MODE=2; // default BR MODE is AUTO
	dDEVICE_MODE=1; // This mode defines if device uses remote (MQTT) management or uses local logics - 0 for remote, 1 for local mode. DEFAULT is 0 - remote

// HTTPD
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
//MQTT
	uart_init(115200, 115200);
	CFG_Load();
	sleepms(1000);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL);
	//MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1);
	//MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1);

//	MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnPublished(&mqttClient, mqttPublishedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	INFO("device_ID:%s\r\n",sysCfg.device_id);
	INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
//DS18B20 timers
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);
// DHT22 initialize
	DHTInit(DHT22, DELAY);
	os_timer_disarm(&dht22_timer);
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DELAY, 1);
// INPUT PIN initialize
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	ETS_GPIO_INTR_ATTACH(read_input_pin, 13); // GPIO13 interrupt handler
	PIN_FUNC_SELECT(PIN_GPIO13_MUX, PIN_GPIO13_FUNC);
	gpio_output_set(0, 0, 0, BIT13); // Set GPIO13 as input
	PIN_PULLUP_EN(PIN_GPIO13_MUX); // Enable pullup
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO12 status
	gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_NEGEDGE); // Interrupt on NEGATIVE GPIO13 edge
	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
//	INFO("Input pin INITIALIZED ! ! !");

// initialize GPIO12
	PIN_FUNC_SELECT(PIN_GPIO12_MUX, PIN_GPIO12_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO12, 0);
//	INFO("GPIO12 set to OFF\r\n");
// initialize GPIO5
	GPIO_OUTPUT_SET(PIN_GPIO5, 0);
//	INFO("GPIO5 set to OFF\r\n");
// initialize GPIO14
	PIN_FUNC_SELECT(PIN_GPIO14_MUX, PIN_GPIO14_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO14, 0);
//	INFO("GPIO14 set to OFF\r\n");
	WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb);

	os_printf("\nReady\n");
}