Пример #1
0
void OtaUpdate() {
	uint8 slot;
	rboot_config bootconf;

	Serial.println("Updating...");

	hardwareTimer.stop();
	reportTimer.stop();

	sendToClients("Firmware ota update started...");

	// need a clean object, otherwise if run before and failed will not run again
	if (otaUpdater)
		delete otaUpdater;
	otaUpdater = new rBootHttpUpdate();

	sendToClients("Firmware ota update started...1");

	// select rom slot to flash
	bootconf = rboot_get_config();
	slot = bootconf.current_rom;
	if (slot == 0)
		slot = 1;
	else
		slot = 0;

#ifndef RBOOT_TWO_ROMS
	// flash rom to position indicated in the rBoot config rom table
	otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL);
#else
	// flash appropriate rom
	if (slot == 0) {
		otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL);
	} else {
		otaUpdater->addItem(bootconf.roms[slot], ROM_1_URL);
	}
#endif

#ifndef DISABLE_SPIFFS
	// use user supplied values (defaults for 4mb flash in makefile)
	if (slot == 0) {
		otaUpdater->addItem(RBOOT_SPIFFS_0, SPIFFS_URL);
	} else {
		otaUpdater->addItem(RBOOT_SPIFFS_1, SPIFFS_URL);
	}
#endif

	sendToClients("Firmware ota update started...2");
	// request switch and reboot on success
	otaUpdater->switchToRom(slot);
	// and/or set a callback (called on failure or success without switching requested)
	otaUpdater->setCallback(OtaUpdate_CallBack);

	// start update
	sendToClients("Firmware ota update started...3");
	otaUpdater->start();
}
Пример #2
0
void reportStatus() {
	char buf[30];
	sprintf(buf, "X%d Y%d Z%d E%d M%d", curPos[x], curPos[y], curPos[z], curPos[e], steppersOn);
	String message = String(buf);
	if (!message.equals(lastPositionMessage)) {
		sendToClients(message);
		lastPositionMessage = message;
	}
}
Пример #3
0
void wsMessageReceived(WebSocket& socket, const String& message) {
	Serial.printf("WebSocket message received: %s\r\n", message.c_str());

	char buf[150];
	sprintf(buf, "WebSocket message received: %s\r\n", message.c_str());
	String msgBack = String(buf);
	sendToClients(msgBack);

	parseGcode(message.c_str());
}
Пример #4
0
void OtaUpdate_CallBack(bool result) {
	sendToClients("OtaUpdate_CallBack");

	Serial.println("In callback...");
	if (result == true) {
		sendToClients("Ota update SUCCESS!");
		// 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);
		sendToClients("Firmware updated, rebooting...");
		rboot_set_current_rom(slot);
		System.restart();
	} else {
		// fail
		sendToClients("Ota update FAIL!");
		Serial.println("Firmware update failed!");
	}
}
Пример #5
0
void onReceive(UdpConnection& connection, char *data, int size, IPAddress remoteIP, uint16_t remotePort)
{
	char buf[60];
	char buf1[12];

	sendToClients("UDP received");
	debugf("UDP Sever callback from %s:%d, %d bytes", remoteIP.toString().c_str(), remotePort, size);

	// We implement string mode server for example
	Serial.print(">\t");
	Serial.print(data);

	floatAnalog = atof(analogResult.c_str()) / 10.0;
	dtostrf(floatAnalog, 7, 4, buf1);
	sprintf(buf, "%s", deblank(buf1));
	String message = String(buf);

	udp.sendStringTo(remoteIP, udpServerPort, message);
}
Пример #6
0
int INetwork::sendToAllClients (const IProtocolMessage& msg)
{
	return sendToClients(0, msg);
}
Пример #7
0
void parseGcode(String commandLine) {
	if (commandLine.equals("ota")) {
		//server.enableWebSockets(false);
		OtaUpdate();
		return;
	} else if (commandLine.equals("switch")) {
		Switch();
		return;
	} else if (commandLine.equals("restart")) {
		System.restart();
		return;
	} else if (commandLine.equals("pos")) {
		reportStatus();
		return;
	} else if (commandLine.equals("enable")) {
		enableMotors();
		return;
	} else if (commandLine.equals("disable")) {
		disableMotors();
		return;
	} else if (commandLine.equals("stop")) {
		for (int i = 0; i < 4; i++) {
			nextPos[i] = curPos[i];
		}
	} else if (commandLine.startsWith("udpServerIP"))
	{
		Vector<String> commandToken;
		int numToken = splitString(commandLine, ' ', commandToken);
		if(numToken==2)
			udpServerIP = commandToken[1];
		if(numToken==3)
		{
			udpServerIP = commandToken[1];
			udpServerPort = atoi(commandToken[2].c_str());
		}
		char buf[150];
		sprintf(buf, "Udp server port %s, port: %d", udpServerIP.c_str(), udpServerPort);
		String msgBack = String(buf);
		sendToClients(msgBack);
		return;

	} else if (commandLine.startsWith("reassign")) {
//sendToClients(message)
//reassign x=3 y=0 z=2 e=1
		Vector<String> commandToken;
		int numToken = splitString(commandLine, ' ', commandToken);
		for (int i = 1; i < numToken; i++) {
			Vector<String> axisIndex;
			String axisIndexStr = commandToken[i].c_str();
			splitString(axisIndexStr, '=', axisIndex);
			String axis = axisIndex[0].c_str();
			if (axis.equals("x"))
				x = atoi(axisIndex[1].c_str());
			else if (axis.equals("y"))
				y = atoi(axisIndex[1].c_str());
			else if (axis.equals("z"))
				z = atoi(axisIndex[1].c_str());
			else if (axis.equals("e"))
				e = atoi(axisIndex[1].c_str());
		}
		char buf[150];
		sprintf(buf, "Reassign: x=%d y=%d z=%d e=%d\r\n", x, y, z, e);
		String msgBack = String(buf);
		sendToClients(msgBack);
		return;
	}

	if (steppersOn) {
		Vector<String> commandToken;
		int numToken = splitString(commandLine, ' ', commandToken);
		for (int i = 0; i < numToken; i++) {
			Serial.printf("Command: %s\r\n", commandToken[i].c_str());
			String motor = commandToken[i].substring(0, 1);
			String sign = commandToken[i].substring(1, 2);
			String posStr = "";
			if (sign == "+" || sign == "-") {
				posStr = commandToken[i].substring(2, commandToken[i].length());
			} else {
				sign = "";
				posStr = commandToken[i].substring(1, commandToken[i].length());
			}
			int8_t index = -1;
			if (motor == "X")
				index = x;
			else if (motor == "Y")
				index = y;
			else if (motor == "Z")
				index = z;
			else if (motor == "E")
				index = e;
			else if (motor == "T") {
				deltat = atoi(posStr.c_str());
			}
			if (index > -1) {
				if (sign == "+")
					nextPos[index] = nextPos[index] + atol(posStr.c_str());
				else if (sign == "-")
					nextPos[index] = nextPos[index] - atol(posStr.c_str());
				else
					nextPos[index] = atol(posStr.c_str());

				char buf[150];
				sprintf(buf, "Set nextpos[%d] to %d\r\n", index, nextPos[index]);
				Serial.printf(buf);
				String msgBack = String(buf);
				sendToClients(msgBack);
			}
		}
	}
}