// Callback for messages, arrived from MQTT server void onMessageReceived(String topic, String message) { if (topic.endsWith("Firmware")) { if (message.equals("UPDATE")) { OtaUpdate(); } } if (topic.endsWith("Lunch")) { if (topic.equals(mqtt_client + "/Lunch")) { // My own message } else { messageSentByMe = false; } if (message.equals("ON")) { indicationState = INDICATION_LUNCH; } else { indicationState = INDICATION_CONNECTED; } } Serial.print(topic); Serial.print(":\r\n\t"); // Pretify alignment for printing Serial.println(message); WifiAccessPoint.enable(false); }
void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCharsCount) { if (arrivedChar == '\n') { char str[availableCharsCount]; for (int i = 0; i < availableCharsCount; i++) { str[i] = stream.read(); if (str[i] == '\r' || str[i] == '\n') { str[i] = '\0'; } } if (!strcmp(str, "connect")) { // connect to wifi WifiStation.config(WIFI_SSID, WIFI_PWD); WifiStation.enable(true); } else if (!strcmp(str, "ip")) { Serial.printf("ip: %s mac: %s\r\n", WifiStation.getIP().toString().c_str(), WifiStation.getMAC().c_str()); } else if (!strcmp(str, "ota")) { OtaUpdate(); } else if (!strcmp(str, "switch")) { Switch(); } else if (!strcmp(str, "restart")) { System.restart(); } else if (!strcmp(str, "ls")) { Vector<String> files = fileList(); Serial.printf("filecount %d\r\n", files.count()); for (unsigned int i = 0; i < files.count(); i++) { Serial.println(files[i]); } } else if (!strcmp(str, "cat")) { Vector<String> files = fileList(); if (files.count() > 0) { Serial.printf("dumping file %s:\r\n", files[0].c_str()); Serial.println(fileGetContent(files[0])); } else { Serial.println("Empty spiffs!"); } } else if (!strcmp(str, "info")) { ShowInfo(); } else if (!strcmp(str, "help")) { Serial.println(); Serial.println("available commands:"); Serial.println(" help - display this message"); Serial.println(" ip - show current ip address"); Serial.println(" connect - connect to wifi"); Serial.println(" restart - restart the esp8266"); Serial.println(" switch - switch to the other rom and reboot"); Serial.println(" ota - perform ota update, switch rom and reboot"); Serial.println(" info - show esp8266 info"); #ifndef DISABLE_SPIFFS Serial.println(" ls - list files in spiffs"); Serial.println(" cat - show first file in spiffs"); #endif Serial.println(); } else { Serial.println("unknown command"); } } }
void onAjaxRunOta(HttpRequest &request, HttpResponse &response) { OtaUpdate(); }
void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCharsCount) { /* Serial.print("Class Delegate Demo Time = "); Serial.print(micros()); Serial.print(" char = 0x"); Serial.print(String(arrivedChar, HEX)); // char hex code Serial.print(" available = "); Serial.println(availableCharsCount); */ int ia = (int) arrivedChar; if (arrivedChar == '\n') // Lets show data! { char str[availableCharsCount]; Serial.println("<New line received>"); int i = 0; while (stream.available()) { char cur = stream.read(); if (((int) cur != 13) && ((int) cur != 10)) { str[i] = cur; Serial.print(cur); } else { str[i] = '\0'; } i++; } Serial.println(); //} /* int ia = (int) arrivedChar; if (ia == 13) { char str[availableCharsCount]; for (int i = 0; i < availableCharsCount-1; i++) { str[i] = stream.read(); Serial.printf("%c",str[i]); if (str[i] == '\r' || str[i] == '\n') { str[i] = '\0'; //break; } } */ Serial.printf("\nCommand: %s, length=%d %d %d\n", str, availableCharsCount, str[availableCharsCount - 2], str[availableCharsCount - 1]); if (!strcmp(str, "connect")) { // connect to wifi WifiStation.config(wifi_sid.get(currWifiIndex), wifi_pass.get(currWifiIndex)); WifiStation.enable(true); } else if (!strcmp(str, "ip")) { Serial.printf("ip: %s mac: %s\r\n", WifiStation.getIP().toString().c_str(), WifiStation.getMAC().c_str()); } else if (!strcmp(str, "ota")) { OtaUpdate(); } else if (!strcmp(str, "restart")) { System.restart(); } else if (!strcmp(str, "ls")) { Vector<String> files = fileList(); Serial.printf("filecount %d\r\n", files.count()); for (unsigned int i = 0; i < files.count(); i++) { Serial.println(files[i]); } } else if (!strcmp(str, "info")) { ShowInfo(); } else if (!strcmp(str, "switch")) { Switch(); } else if (!strcmp(str, "cat")) { Vector<String> files = fileList(); if (files.count() > 0) { Serial.printf("dumping file %s:\r\n", files[2].c_str()); Serial.println(fileGetContent(files[2])); } else { Serial.println("Empty spiffs!"); } } else if (!strcmp(str, "pos")) { reportStatus(); } else if (!strcmp(str, "move")) { Serial.println(); nextPos[0] += 10000; nextPos[1] += 10000; nextPos[2] += 10000; nextPos[3] += 10000; //procTimer.initializeUs(deltat, blink1).start(true); } else if (!strcmp(str, "help")) { Serial.println(); Serial.println("available commands:"); Serial.println(" help - display this message"); Serial.println(" ip - show current ip address"); Serial.println(" connect - connect to wifi"); Serial.println(" restart - restart the esp8266"); Serial.println(" switch - switch to the other rom and reboot"); Serial.println(" ota - perform ota update, switch rom and reboot"); Serial.println(" info - show esp8266 info"); #ifndef DISABLE_SPIFFS Serial.println(" ls - list files in spiffs"); Serial.println(" cat - show first file in spiffs"); #endif Serial.println(); } else { Serial.printf("Trying to parse as gCode: %s\n", str); parseGcode(str); } } else if (ia == 48) { Serial.println(); stream.read(); nextPos[0] += 100; nextPos[1] += 100; nextPos[2] += 100; nextPos[3] += 100; //procTimer.initializeUs(deltat, blink1).start(true); } else if (ia == 49) { Serial.println(); stream.read(); nextPos[0] -= 100; nextPos[1] -= 100; nextPos[2] -= 100; nextPos[3] -= 100; //procTimer.initializeUs(deltat, blink1).start(true); } }
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); } } } }
void cmdOTA(String commandLine, CommandOutput* commandOutput) { OtaUpdate(); }