Skip to content

Commit

Permalink
Auto stash before merge of "master" and "origin/master"
Browse files Browse the repository at this point in the history
  • Loading branch information
tretyakovsa committed Oct 11, 2017
1 parent 085e59a commit 0c65f99
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 69 deletions.
7 changes: 1 addition & 6 deletions Event.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void initDHT() {
String temp = "";
temp += dht.getTemperature();
if (temp != "nan") {
//Serial.println("ok");
HTTP.on("/temperature.json", HTTP_GET, []() {
float temp = dht.getTemperature();
if (temp == 'NaN') {
Expand All @@ -95,7 +94,6 @@ void initD18B20() {
d18b20.requestTemperatures();
float ok = d18b20.getTempCByIndex(0);
d18b20.setResolution(12);
//Serial.println(ok);
if (ok != -127) {
HTTP.on("/temperature.json", HTTP_GET, []() {
d18b20.requestTemperatures();
Expand Down Expand Up @@ -127,10 +125,7 @@ void RCRCreceiv() {
if (value == 0) {
configJson = jsonWrite(configJson, "Received", 0);
} else {
int codeRC = mySwitch.getReceivedValue();
//Serial.print("Received ");
//Serial.println(codeRC);
//configJson = jsonWrite(configJson, "Received", codeRC);
int codeRC = mySwitch.getReceivedValue();
flag = sendStatus("Received", codeRC);
}
mySwitch.resetAvailable();
Expand Down
6 changes: 1 addition & 5 deletions MQTTDDNS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ void callback(const MQTT::Publish& pub)
//if (String(pub.topic()) == prefix + "/"+chipID + "/RELE_1_not/status") // проверяем из нужного ли нам топика пришли данные
{
int stled = payload.toInt(); // преобразуем полученные данные в тип integer
//Serial.println(stled);
if (stled == 1) command = "relayon";
if (stled == 0) command = "relayoff";
//Serial.println(command);


}

Expand All @@ -45,17 +44,14 @@ void MQTT_Pablush() {
// подключаемся к MQTT серверу
if (WiFi.status() == WL_CONNECTED) {
if (!client.connected()) {
//Serial.println("Connecting to MQTT server");
if (client.connect(MQTT::Connect(chipID)
.set_auth(jsonRead(configSetup, "mqttUser"), jsonRead(configSetup, "mqttPass")))) {
//Serial.println("Connected to MQTT server");
client.set_callback(callback);
client.subscribe(prefix); // Для приема получения HELLOW и подтверждения связи
client.subscribe(prefix + "/+/+/control"); // Подписываемся на топики control
//client.subscribe("/" + chipID + "/RELE_1"); // подписываемся по топик с данными для светодиода
loadnWidgets();
} else {
//Serial.println("Could not connect to MQTT server");
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions Main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ String modulesInit(String json, String nameArray) {
int k = nestedArray.size();
for (int i = 0; i <= k - 1; i++) {
String temp = All[nameArray][i]["type"];
Serial.println( temp );
sCmd.readStr(temp);
}
return "OK";
Expand All @@ -239,8 +238,6 @@ String goCommands(String inits) {
inits += rn;
do {
temp = selectToMarker (inits, rn);
//Serial.print("command=");
//Serial.println(temp);
sCmd.readStr(temp);
inits = deleteBeforeDelimiter(inits, rn);
} while (inits.indexOf(rn) != 0);
Expand Down
3 changes: 0 additions & 3 deletions NTP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ void timeSynch(int zone) {
// Инициализация UDP соединения с NTP сервером
configTime(zone * 3600, 0, "pool.ntp.org", "ru.pool.ntp.org");
int i = 0;
//Serial.print("\nWaiting for time ");
while (!time(nullptr) && i < 10) {
//Serial.print(".");
i++;
delay(100);
}
Serial.println("");
String timeNow = GetTime();
configJson = jsonWrite(configJson, "time", timeNow);
configSetup = jsonWrite(configSetup, "time", timeNow);
Expand Down
2 changes: 0 additions & 2 deletions Relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ String relayStatus(String json, String state) {
return out;
}
void relayOn() {
Serial.println(getStatusInt("stateRelay"));
if (!getStatusInt("stateRelay")) flag = sendStatus("stateRelay", 1);
digitalWrite(getOptionsInt("relay1Pin"), getStatusInt("stateRelay"));
toggleRelay(getStatusInt("stateRelay"));
topicPub("/RELE_1_not/status", String(getStatusInt("stateRelay")), 1 );
}

void relayOff() {
Serial.println(getStatusInt("stateRelay"));
if (getStatusInt("stateRelay")) flag = sendStatus("stateRelay", 0);
digitalWrite(getOptionsInt("relay1Pin"), getStatusInt("stateRelay"));
toggleRelay(getStatusInt("stateRelay"));
Expand Down
8 changes: 0 additions & 8 deletions SSDP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void handle_device() {
configOptions = jsonWrite(configOptions, "SSDP", ssdpName);
modules = jsonWrite(modules, "SSDP", ssdpName);
SSDP.setName(ssdpName);
//Serial.println(jsonRead(configSetup, "SSDP"));
SSDP.setModelNumber(chipID + "/" + jsonRead(configSetup, "SSDP"));
String space = HTTP.arg("space");
configSetup = jsonWrite(configSetup, "space", space);
Expand Down Expand Up @@ -90,20 +89,14 @@ void handleUDP() {
int len = udp.read(packetBuffer, 512);
if (len > 0) packetBuffer[len] = 0;
input_string += packetBuffer;
//Serial.println(input_string);
int i = input_string.indexOf("Arduino");
if (i > 0) {

chipIDremote = deleteBeforeDelimiter(input_string, "Arduino");
//Serial.println(chipIDremote);
chipIDremote = selectToMarker(chipIDremote, "\n");
//Serial.println(chipIDremote);
//1.0 UPNP/1.1 smart-room/4039-1458400/IoT-Room 2 (\n)
ssdpName = selectToMarkerLast(chipIDremote, "/");
ssdpName = selectToMarker(ssdpName, "\r");
//Serial.println(ssdpName);
//ssdpName = selectToMarker(ssdpName, "/");
//Serial.println(ssdpName);
chipIDremote = selectToMarkerLast(chipIDremote, "/");
chipIDremote = selectToMarker(chipIDremote, "\r");
// строку input_string сохраняю для расширения
Expand All @@ -122,7 +115,6 @@ void ssdpLists(String chipIDremote, String remoteIP, String ssdpName ) {
record["ssdp"] = ssdpName;
addressList = "";
list.printTo(addressList);
//list.printTo(Serial);
}

// Каждые 30 секунд проверяем не изиенился ли адрес ip
Expand Down
19 changes: 13 additions & 6 deletions Sonoff_WiFi_switch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ String configLive = "{}"; // Здесь внутренние данн
String ssdpList = "{}";
String regCommands = "{}";
String jsonTimer = "{}";
String previousSetup;
String Scenary;
String Timerset = "";
String modules = "{\"ip\":\"\",\"SSDP\":\"\",\"space\":\"\",\"module\":[]}";
Expand All @@ -84,17 +85,23 @@ boolean thenOk;

void setup() {

//Serial.println (ESP.getResetReason());
//Serial.begin(115200);
delay(100);
//delay(100);
TickerScheduler(1);
Serial.println ("");
Serial.println ("Load");
initCMD();
chipID = String( ESP.getChipId() ) + "-" + String( ESP.getFlashChipId() );
FS_init(); // Включаем работу с файловой системой
// ----------------- начинаем загрузку
configSetup = readFile("config.save.json", 4096);

//previousSetup = configSetup;
//configSetup ="{}";
//Serial.println(configSetup);
//savePrevious();




configSetup = jsonWrite(configSetup, "time", "00:00:00");
//configJson = jsonWrite(configJson, "setIndex", jsonRead(configSetup, "setIndex"));
configOptions = jsonWrite(configOptions, "lang", jsonRead(configSetup, "lang"));
Expand All @@ -114,7 +121,7 @@ void setup() {
sCmd.readStr("SSDP");
sCmd.readStr("HTTP");
// ----------- Выполняем запуск кофигурации
Serial.println(goCommands(test));
goCommands(test);
test = "";
configSetup = jsonWrite(configSetup, "mac", WiFi.macAddress().c_str());
configSetup = jsonWrite(configSetup, "ip", WiFi.localIP().toString());
Expand All @@ -124,7 +131,7 @@ void setup() {

void loop() {
ts.update();
sCmd.readStr(command); // We don't do much, just process serial commands
sCmd.readStr(command);
command = "";
dnsServer.processNextRequest();
HTTPWAN.handleClient();
Expand Down
4 changes: 0 additions & 4 deletions Timers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void handle_timer_Mod(){
String responsB ="{}";
String responsC ="{}";

Serial.println(modules);
responsC = jsonWrite(responsC, "rgb", "RGB");
responsC = jsonWrite(responsC, "relay", "Relay");
responsC = jsonWrite(responsC, "jalousie", "Jalousie");
Expand Down Expand Up @@ -72,7 +71,6 @@ void handle_timer_Del() {
DynamicJsonBuffer jsonBuffer;
JsonObject& Timers = jsonBuffer.parseObject(jsonTimer);
JsonArray& nestedArray = Timers["timer"].asArray();
//nestedArray.printTo(Serial);
int y;
for (int i = 0; i <= nestedArray.size() - 1; i++) {
if (Timers["timer"][i]["id"] == HTTP.arg("id").toInt()) y = i;
Expand Down Expand Up @@ -108,7 +106,6 @@ bool loadTimer() {
Timerset += "\r\n";
}
}
Serial.println(Timerset);
}
//runTimers();
return true;
Expand Down Expand Up @@ -152,7 +149,6 @@ void runTimers() {
// выполняем необходимое действие

command = module + com + " " + interval + " " + id;
Serial.println(command);

}
timers = timers.substring(timers.indexOf("\r\n") + 2);
Expand Down
40 changes: 36 additions & 4 deletions Upgrade.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ void initUpgrade() {
}
// ----------------------- Обновление с сайта
void webUpgrade() {
Serial.println("Update module...");
String refresh = "<html><head><meta http-equiv=\"refresh\" content=\"40;/\">Update module...</head></html>";
HTTP.send(200, "text/html", refresh);
String spiffsData = HTTP.arg("spiffs");
if (spiffsData != "") {
SPIFFS.format();
spiffsData = spiffsData.substring(spiffsData.lastIndexOf("/") + 1); // выделяем имя файла
Serial.println(spiffsData);
ESPhttpUpdate.rebootOnUpdate(false);
t_httpUpdate_return ret = ESPhttpUpdate.updateSpiffs(HTTP.arg("spiffs"));
switch(ret) {
Expand All @@ -37,10 +35,44 @@ switch(ret) {
String buildData = HTTP.arg("build");
if (buildData != "") {
buildData = buildData.substring(buildData.lastIndexOf("/") + 1); // выделяем имя файла
Serial.println(buildData);
configSetup = jsonWrite(configSetup, "buildData", buildData);
configSetup = jsonWrite(configSetup, "buildData", buildData);
saveConfigSetup ();
ESPhttpUpdate.rebootOnUpdate(true);
t_httpUpdate_return jet = ESPhttpUpdate.update(HTTP.arg("build"));
}
}

void savePrevious(){
moveSetup ("lang");
moveSetup ("setIndex");
moveSetup ("SSDP");
moveSetup ("space");
moveSetup ("ssid");
moveSetup ("ssidPass");
moveSetupInt ("wifiConnect");
moveSetupInt ("wifiBlink");
moveSetup ("checkboxIP");
moveSetup ("ip");
moveSetup ("subnet");
moveSetup ("getway");
moveSetup ("dns");
moveSetupInt ("timeZone");
moveSetup ("ssidAP");
moveSetup ("ssidApPass");
moveSetup ("configs");
moveSetup ("ddns");
moveSetup ("ddnsName");
moveSetupInt ("ddnsPort");
moveSetup ("mqttServer");
moveSetupInt ("mqttPort");
moveSetup ("mqttUser");
moveSetup ("mqttPass");
}

void moveSetup (String Name){
configSetup = jsonWrite(previousSetup, Name, jsonRead(previousSetup, Name));
}

void moveSetupInt (String Name){
configSetup = jsonWrite(previousSetup, Name, jsonReadtoInt(previousSetup, Name));
}
12 changes: 0 additions & 12 deletions WIFI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ bool RestartWiFi() {

wifiConnect(jsonReadtoInt(configSetup, "wifiConnect"), jsonReadtoInt(configSetup, "wifiBlink"));

Serial.println("");
Serial.println(WiFi.localIP());
// {"title":"<h3>{{LangConnect2}} <a href="http://192.168.1.30">http://192.168.1.30</a></h3>"}
// {"title":"Любой текст и html","class":"класс", "style":"Стиль","state":"Данные для вставки в state input_а"}
String state = "\{\"title\":\"<h3>\{\{LangConnect2\}\} <a href=http://" + WiFi.localIP().toString() + ">http://" + WiFi.localIP().toString() + "</a></h3>\"\}";
Serial.println(state);
HTTP.send(200, "application/json", state);
delay(1000);
// Отключаем точку доступа и переподключаемся к роутеру
Expand All @@ -86,7 +83,6 @@ bool RestartWiFi() {
boolean startSTA(String configWiFi) {
//WiFi.persistent (false);
if (jsonRead(configWiFi, "checkboxIP") == "1") {
Serial.println ("checkboxIP");
IPAddress staticIP;
IPAddress staticGateway;
IPAddress staticSubnet;
Expand All @@ -108,16 +104,11 @@ boolean startSTA(String configWiFi) {
check = false;
}
if (!check) {
Serial.println ("check");
Serial.println (WiFi.config(staticIP, staticGateway, staticSubnet));
Serial.println (WiFi.subnetMask ());
Serial.println (WiFi.gatewayIP ());
}
}
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.hostname ( "sonoff-" + chipID );
Serial.println(WiFi.SSID());
WiFi.begin();
//WiFi.begin(jsonRead(configJson, "ssid").c_str(),jsonRead(configJson, "ssidPass").c_str());
if ( wifiConnect(jsonReadtoInt(configSetup, "wifiConnect"), jsonReadtoInt(configSetup, "wifiBlink"))) {
Expand All @@ -140,7 +131,6 @@ boolean wifiConnect(byte tries, byte pin) {
{
//Мигаем сетодиодом при попытке подключится к роутеру
if (pin != 0) digitalWrite(pin, HIGH);
Serial.print(".");
delay(500);
if (pin != 0) digitalWrite(pin, LOW);
delay(500);
Expand Down Expand Up @@ -190,10 +180,8 @@ void handle_wifi_scan() {
// ----------------- Запускаем WiFi
void startWIFI() {
if (startSTA(configSetup)) {
//Serial.println(WiFi.localIP().toString());
}
else {
startAP(configSetup);
//Serial.println("Start AP");
}
}
Loading

0 comments on commit 0c65f99

Please sign in to comment.