In my old code, I share some info as position, close/open time and some others, with my mqtt server, ios and android app, so commands are always specular, if I give supla command, I see in real time, for example, the position of rollershutter on my app and vice-versa, To do this in old code I used "setStatusFuncImpl" to take supla status connection and send the info to mqtt server
Code: Select all
void status_func(int status, const char *msg) {
s = status;
}
To take variables of position, and config close/open time, I used "setStatusFuncImpl" as:
Code: Select all
.......... supla declarations.....
SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
.......
void supla_rs_SavePosition(int channelNumber, int position) {
intlivello = position;
if ((!digitalRead(relay_1)) && (!digitalRead(relay_2))) {
inttmp0 = position;
savers0 = true;
}
if (position <= 100 || position >= 10100) {
inttmp0 = position;
SuplaDevice.rollerShutterStop(0);
savers0 = true;
}
}
void supla_rs_LoadPosition(int channelNumber, int *position) {
//SuplaDevice.StopTimer();
readPosFile();
position = intlivello;
//EEPROM.get(2, *position);
Serial.print("read position R1: ");
Serial.println(*position);
//intlivello = *position;
//Serial.println(intlivello);
motoron = true;
//SuplaDevice.StartTimer();
}
void supla_rs_SaveSettings(int channelNumber, unsigned int full_opening_time, unsigned int full_closing_time) {
SuplaDevice.StopTimer();
full_opening_time = full_opening_time / 1000;
full_closing_time = full_closing_time / 1000;
String(full_opening_time).toCharArray(tempochar, 4);
String(full_closing_time).toCharArray(tempochar2, 4);
Serial.println(tempochar);
Serial.println(tempochar2);
if (writeConfigFile()) {
publishTime1 = true;
publishTime2 = true;
}
/*
EEPROM.put(50, full_opening_time);
EEPROM.put(55, full_closing_time);
EEPROM.commit();
SuplaDevice.StartTimer();
}
void supla_rs_LoadSettings(int channelNumber, unsigned int *full_opening_time, unsigned int *full_closing_time) {
//SuplaDevice.StopTimer();
//EEPROM.get(50, *full_opening_time);
//EEPROM.get(55, *full_closing_time);
readConfigFile();
Serial.println("sono nel ciclo supla");
full_opening_time = tempo * 1000;
full_closing_time = tempo2 * 1000;
Serial.print("read R1--channel: "); Serial.print((channelNumber)); Serial.print(" opening_time "); Serial.print((*full_opening_time)); Serial.print(" closing_time "); Serial.println((*full_closing_time));
//SuplaDevice.StartTimer();
}
so I can share variables with mqtt server topics.