Ejemplo n.º 1
0
void mount_spiffs(){

	int slot = rboot_get_current_rom();

#ifndef DISABLE_SPIFFS
	if (slot == 0) {
#ifdef RBOOT_SPIFFS_0
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
		spiffs_mount_manual(0x40300000, SPIFF_SIZE);
#endif
	} else {
#ifdef RBOOT_SPIFFS_1
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
		spiffs_mount_manual(0x40500000, SPIFF_SIZE);
#endif
	}
#else
	debugf("spiffs disabled");
#endif

}
Ejemplo n.º 2
0
void Switch() {
	uint8 before, after;
	before = rboot_get_current_rom();
	if (before == 0) after = 1; else after = 0;
	Serial.printf("Swapping from rom %d to rom %d.\r\n", before, after);
	rboot_set_current_rom(after);
	Serial.println("Restarting...\r\n");
	System.restart();
}
Ejemplo n.º 3
0
void otaUpdate_CallBack(bool result) {
	
    Debug.println("In OTA callback...");
    if(result == true)
    {
        // success
        uint8 slot;
        slot = rboot_get_current_rom();
        if (slot == 0) slot = 1; else slot = 0;
#ifndef DISABLE_SPIFFS
        Debug.printf("Firmware updated, storing AppSettings to new spiffs...\r\n");
        AppSettings.load();
        spiffs_unmount();
        if (slot == 0)
        {
#ifdef RBOOT_SPIFFS_0
            Debug.printf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
#else
            Debug.printf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
            spiffs_mount_manual(0x40300000, SPIFF_SIZE);
#endif
        }
        else
        {
#ifdef RBOOT_SPIFFS_1
            Debug.printf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
            spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
#else
            Debug.printf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
            spiffs_mount_manual(0x40500000, SPIFF_SIZE);
#endif
        }
        AppSettings.save();
#else
        Debug.printf("spiffs disabled");
#endif
        // set to boot new rom and then reboot
        Debug.printf("Firmware updated, rebooting to rom %d...\r\n", slot);
        rboot_set_current_rom(slot);
        System.restart();
    }
    else
    {
        // fail
        Debug.println("Firmware update failed!");
        if (numOtaTrials < 6)
            StartOtaUpdate();
        else
            numOtaTrials = 0;
    }
}
Ejemplo n.º 4
0
void OtaUpdate_CallBack(bool result) {
	Serial.println("In callback...");
	if(result == true) {
		// success
		uint8 slot;
		slot = rboot_get_current_rom();
		if (slot == 0) slot = 1; else slot = 0;
		// set to boot new rom and then reboot
		Serial.printf("Firmware updated, rebooting to rom %d...\r\n", slot);
		rboot_set_current_rom(slot);
		System.restart();
	} else {
		// fail
		Serial.println("Firmware update failed!");
	}
}
Ejemplo n.º 5
0
void init() {
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(false); // Debug output to serial
	
	// mount spiffs
	int slot = rboot_get_current_rom();

	if (slot == 0) {
#ifdef RBOOT_SPIFFS_0
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
		spiffs_mount_manual(0x40300000, SPIFF_SIZE);
#endif
	} else {
#ifdef RBOOT_SPIFFS_1
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
		spiffs_mount_manual(0x40500000, SPIFF_SIZE);
#endif
	}

	WifiAccessPoint.enable(false);
	WifiStation.config(WIFI_SSID, WIFI_PWD);
    WifiStation.enable(true);
	
    Serial.printf("\r\nCurrently running rom %d.\r\n", slot);
	Serial.println("Type 'help' and press enter for instructions.");
	Serial.println();
	Serial.commandProcessing(true);
    
    commandHandler.registerCommand(CommandDelegate("ip","show current ip address","user", cmdIP));
    commandHandler.registerCommand(CommandDelegate("ota","perform ota update, switch rom and reboot","user", cmdOTA));
    commandHandler.registerCommand(CommandDelegate("heap","display free heap","user", cmdAppHeap));
    commandHandler.registerCommand(CommandDelegate("ls","list files in spiffs","user", cmdLs));
    commandHandler.registerCommand(CommandDelegate("connect","connect to wifi","user", cmdConnect));
    commandHandler.registerCommand(CommandDelegate("disconnect","disconnect from wifi","user", cmdConnect));
    commandHandler.registerCommand(CommandDelegate("ap","create access point","user", cmdAP));
    
	//Serial.setCallback(serialCallBack);
    init_servos(); 
    WifiStation.waitConnection(startWebServer, 30, startAP);    
    
}
Ejemplo n.º 6
0
/**
 * @brief      Callback after an ota is done
 *
 * @param[in]  result  Tells whether an OTA is successful or not
 */
void ota_onUpdate(bool result) {
	
	PRINTF_INFO("OTA Update Callback...");

	if(result == true) {
		// success
		uint8 slot;
		slot = rboot_get_current_rom();
		if (slot == 0) slot = 1; else slot = 0;
		// set to boot new rom and then reboot
		PRINTF_INFO("Firmware updated, rebooting to rom %d...\r\n", slot);
		rboot_set_current_rom(slot);
		System.restart();
	} else {
		// fail
		PRINTF_ERR("Firmware update failed!\n");
	}
}
Ejemplo n.º 7
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());
	}

}
Ejemplo n.º 8
0
/**
 * show system information
 */
void onSystem(HttpRequest &request, HttpResponse &response)
{
	if (request.getRequestMethod() == RequestMethod::POST)
	{
//		AppSettings.dhcp = request.getPostParameter("dhcp") == "1";
//		AppSettings.ip = request.getPostParameter("ip");
//		AppSettings.netmask = request.getPostParameter("netmask");
//		AppSettings.gateway = request.getPostParameter("gateway");
//		debugf("Updating IP settings: %d", AppSettings.ip.isNull());
//		AppSettings.save();
	}

	TemplateFileStream *tmpl = new TemplateFileStream("system.html");
	auto &vars = tmpl->variables();


	vars["buildref"]=BUILD_GITREF;
	vars["buildtime"]=VERSION " " BUILD_TIME;


	String rom(rboot_get_current_rom());
	vars["bootrom"]=rom;

	bool dhcp = WifiStation.isEnabledDHCP();
	vars["dhcpon"] = dhcp ? "checked='checked'" : "";
	vars["dhcpoff"] = !dhcp ? "checked='checked'" : "";

	if (!WifiStation.getIP().isNull())
	{
		vars["ip"] = WifiStation.getIP().toString();
		vars["netmask"] = WifiStation.getNetworkMask().toString();
		vars["gateway"] = WifiStation.getNetworkGateway().toString();
	}
	else
	{
		vars["ip"] = "192.168.1.77";
		vars["netmask"] = "255.255.255.0";
		vars["gateway"] = "192.168.1.1";
	}

	response.sendTemplate(tmpl); // will be automatically deleted
}
Ejemplo n.º 9
0
void init() {

	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Debug output to serial
	//commandHandler.registerSystemCommands();

	// Enable rboot in makefile!
	int slot = rboot_get_current_rom();
	Serial.printf("\r\nCurrently running rom %d.\r\n", slot);


	if (!digitalRead(SWITCH_PIN)) {

			// Reboot in operation-mode
			rboot_set_current_rom(0);
			Serial.println("Restarting...");
			System.restart();
		}

	pinMode(GREEN_LED_PIN, OUTPUT);
	pinMode(RED_LED_PIN, OUTPUT);
	pinMode(SWITCH_PIN, INPUT);

	WifiStation.enable(true);
	WifiStation.enableDHCP(true);

	WifiAccessPoint.enable(false);

	configMode = false;
	smartConfigActive = false;

	debounceTimer.initializeMs(1200, debounceReset);
	configTimer.initializeMs(1000, switchDelay);
	attachInterrupt(SWITCH_PIN, switchPressed, RISING);

	setConfigMode(true);

}
Ejemplo n.º 10
0
void init() {
	
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Debug output to serial
	
	// mount spiffs
	int slot = rboot_get_current_rom();
#ifndef DISABLE_SPIFFS
	if (slot == 0) {
#ifdef RBOOT_SPIFFS_0
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE);
		spiffs_mount_manual(0x40300000, SPIFF_SIZE);
#endif
	} else {
#ifdef RBOOT_SPIFFS_1
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE);
		spiffs_mount_manual(0x40500000, SPIFF_SIZE);
#endif
	}
#else
	debugf("spiffs disabled");
#endif
	WifiAccessPoint.enable(false);
	
	Serial.printf("\r\nCurrently running rom %d.\r\n", slot);
	Serial.println("Type 'help' and press enter for instructions.");
	Serial.println();
	
	Serial.setCallback(serialCallBack);
}
Ejemplo n.º 11
0
void init() {
	pinMode(PIN_BUTTON, INPUT);
	pinMode(PIN_GREEN, OUTPUT);
	pinMode(PIN_BLUE, OUTPUT);
	pinMode(PIN_RED, OUTPUT);
	digitalWrite(PIN_GREEN,0); //Green
	digitalWrite(PIN_BLUE,0); //Blue
	digitalWrite(PIN_RED,0); //Red

	indicationTimer.initializeMs(50, indicationFunction).start(); // every 20 seconds
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Debug output to serial

	
	// mount spiffs
	int slot = rboot_get_current_rom();
#ifndef DISABLE_SPIFFS
	if (slot == 0) {
#ifdef RBOOT_SPIFFS_0
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 , SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_0, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x100000, SPIFF_SIZE);
		spiffs_mount_manual(0x100000, SPIFF_SIZE);
#endif
	} else {
#ifdef RBOOT_SPIFFS_1
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 , SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_1, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", SPIFF_SIZE);
		spiffs_mount_manual(0x300000, SPIFF_SIZE);
#endif
	}
#else
	debugf("spiffs disabled");
#endif
	AppSettings.load();

	WifiAccessPoint.enable(false);
	// connect to wifi
	WifiStation.config(WIFI_SSID, WIFI_PWD);
	WifiStation.enable(true);
	
	if (AppSettings.exist())
	{
		WifiStation.config(AppSettings.ssid, AppSettings.password);
		if (!AppSettings.dhcp && !AppSettings.ip.isNull())
			WifiStation.setIP(AppSettings.ip, AppSettings.netmask, AppSettings.gateway);
	}
	mqtt = new MqttClient(AppSettings.mqtt_server,AppSettings.mqtt_port, onMessageReceived);

	WifiStation.startScan(networkScanCompleted);

	// Start AP for configuration
	WifiAccessPoint.enable(true);
	WifiAccessPoint.config("Sming Configuration "+ WifiStation.getMAC(), "", AUTH_OPEN);

	// Run WEB server
	startWebServer();
	
	Serial.printf("\r\nCurrently running rom %d.\r\n", slot);
	Serial.println("Type 'help' and press enter for instructions.");
	Serial.println();
	
	Serial.setCallback(serialCallBack);
	// Run our method when station was connected to AP (or not connected)
	WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for connection timeout at start
}
Ejemplo n.º 12
0
void init() {
//ets_wdt_disable();
	Serial.begin(115200);
	WifiStation.enable(false);
	System.setCpuFrequency(eCF_160MHz);
	//Serial.systemDebugOutput(true);
	Serial.println("************************");
	Serial.println("***** Init running *****");
	Serial.println("************************");

// mount spiffs

	int slot = rboot_get_current_rom();
#ifndef DISABLE_SPIFFS
	if (slot == 0) {
#ifdef RBOOT_SPIFFS_0
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 , SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_0, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", 0x100000, SPIFF_SIZE);
		spiffs_mount_manual(0x100000, SPIFF_SIZE);
#endif
	} else {
#ifdef RBOOT_SPIFFS_1
		debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 , SPIFF_SIZE);
		spiffs_mount_manual(RBOOT_SPIFFS_1, SPIFF_SIZE);
#else
		debugf("trying to mount spiffs at %x, length %d", SPIFF_SIZE);
		spiffs_mount_manual(0x300000, SPIFF_SIZE);
#endif
	}
#else
	debugf("spiffs disabled");
#endif


	//wifi_sid.add("linksys");
	//wifi_pass.add("Doitman1");
	wifi_sid.add("Sintex");
	wifi_pass.add("sintex92");
	wifi_sid.add("AsusKZ");
	wifi_pass.add("Doitman1");
	//wifi_sid.add("AndroidAp");
	//wifi_pass.add("Doitman1");

	WifiStation.config(wifi_sid.get(currWifiIndex), wifi_pass.get(currWifiIndex));
	WifiAccessPoint.enable(false);
	WifiStation.enable(true);


	procTimer.initializeMs(20000, checkConnection).start();

	WifiEvents.onStationGotIP(connectOk);

	//WifiStation.waitConnection(connectOk, 10, connectNotOk);

	/*


	 //wifi_set_opmode (STATION_MODE);
	 WifiAccessPoint.enable(false);

	 wifi_sid.add("AndroidAp");
	 wifi_pass.add("Doitman1");

	 //WifiStation.config(wifi_sid.get(currWifiIndex) , wifi_pass.get(currWifiIndex));
	 WifiStation.config(wifi_sid.get(currWifiIndex), wifi_pass.get(currWifiIndex));

	 WifiEvents.onStationDisconnect(STADisconnect);

	 checkConnection();
	 //WifiStation.connect();
	 //WifiStation.waitConnection(connectOk, 20, connectNotOk);

	 //pinMode(LED_PIN, OUTPUT);
	 procTimer.initializeMs(1000, blink).start();
	 */
}
Ejemplo n.º 13
0
void init()
{
	_wdgHw._init();
	ds1820.init();

    ETS_GPIO_INTR_DISABLE();

	_gpio_init();

    ETS_GPIO_INTR_ATTACH((void*)gpio_intr_handler, NULL);

_uart0._conf(_BAUD_RATE_115200,_EIGHT_BITS,_TWO_STOP_BIT,_NONE_PARITY);

	// Config GPIO
	_gpio0._conf(_INTERRUPT,_PULL_NONE,_OFF,_INTR_POSEDGE);// S_REED
	//_gpio1._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// TXD0
	_gpio2._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
	//_gpio3._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// RXD0
	_gpioDtcNull._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// DTC_NULL
	_gpio5._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
	_gpio12._conf(_INPUT,_PULL_NONE,_ON,_INTR_DISABLE);// TEMP-IO (DS1820)
	_gpioRelay._conf(_OUTPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// CMD_RELAY
	_gpioAm2320._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);// TEMP-IO (AM2320)
	_gpio15._conf(_INPUT,_PULL_NONE,_OFF,_INTR_DISABLE);//
_gpioWdg._conf(_OUTPUT,_PULL_NONE,_ON,_INTR_DISABLE);// WDG_H + LED

	Serial.systemDebugOutput(true);

	_wdgHw.start();

	// _fileSys._mountFileSystem();

	// _fileSys._readCalandarFile();

	WifiAccessPoint.enable(false);
	WifiStation.enable(true);

	WifiStation.config(WIFI_SSID, WIFI_PWD);

#if IS_FIX_IP == 1
	IPAddress _ip;
	_ip = IPAddress(ADDR_IP_ESP);
	WifiStation.setIP(_ip);
	//WifiStation.enableDHCP(false);
#endif

	WifiStation.waitConnection(connectCb);
	


	debugf("\n\n\n");
	debugf("\r\nVersion %s\r\n", VERSION);

	int slot = rboot_get_current_rom();
	debugf("\r\nCurrently running rom %d.\r\n", slot);

	

	os_printf("restart system %s RADIATOR 0.0.0 %s\n\r",VERSION,WifiStation.getMAC().c_str());
	
	//ds1820.start();
	
	_am2320._start();

	_adc._start();
	
	networkTask.start();
}