//---------------------------------------------------------------------------- // //---------------------------------------------------------------------------- void CApplication::cmdOnShow(String commandLine, CommandOutput* pOut) { pOut->println(fileGetContent(CAPP_CONF_FILE)); pOut->println(""); pOut->println(fileGetContent(CMQTT_CONF_FILE)); pOut->println(""); pOut->println(fileGetContent(CNETWORK_CONF_FILE)); pOut->println(""); } // cmdOnShow
MeteoConfig loadConfig() { DynamicJsonBuffer jsonBuffer; MeteoConfig cfg; if (fileExist(METEO_CONFIG_FILE)) { int size = fileGetSize(METEO_CONFIG_FILE); char* jsonString = new char[size + 1]; fileGetContent(METEO_CONFIG_FILE, jsonString, size + 1); JsonObject& root = jsonBuffer.parseObject(jsonString); JsonObject& network = root["network"]; cfg.NetworkSSID = String((const char*)network["ssid"]); cfg.NetworkPassword = String((const char*)network["password"]); JsonObject& correction = root["correction"]; cfg.AddT1 = correction["T1"]; cfg.AddT2 = correction["T2"]; cfg.AddTZ = correction["TZ"]; JsonObject& trigger = root["trigger"]; cfg.Trigger = (TriggerType)(int)trigger["type"]; cfg.RangeMin = trigger["min"]; cfg.RangeMax = trigger["max"]; delete[] jsonString; } else { cfg.NetworkSSID = WIFI_SSID; cfg.NetworkPassword = WIFI_PWD; } return cfg; }
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 CApplication::confLoad() { DynamicJsonBuffer jsonBuffer; if (!confExists()) confSave(); if (confExists()) { int size = fileGetSize(CAPP_CONF_FILE); char* strJson = new char[size + 1]; fileGetContent(CAPP_CONF_FILE, strJson, size + 1); JsonObject& root = jsonBuffer.parseObject(strJson); m_cpuBoost = root["cpuBoost"]; m_otaBaseUrl = (const char *)root["otaBaseUrl"]; m_gpiodEmul = root["emul"]; m_gpiodMode = root["mode"]; m_gpiodLock = root["lock"]; m_gpiodDisable = root["disable"]; m_gpiodInDebounce[0] = root["in0Debounce"]; m_gpiodInDebounce[1] = root["in1Debounce"]; m_gpiodInDebounce[2] = root["in2Debounce"]; m_gpiodInDebounce[3] = root["in3Debounce"]; m_gpiodOutDefRun[0] = root["out0DefRun"]; m_gpiodOutDefRun[1] = root["out1DefRun"]; m_gpiodOutDefRun[2] = root["out2DefRun"]; m_gpiodOutDefRun[3] = root["out3DefRun"]; m_gpiodUdmDefRun[0] = root["udm0DefRun"]; m_gpiodUdmDefRun[1] = root["udm1DefRun"]; delete[] strJson; } } // confLoad
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); } }