how to in new supla device, with old rolleshutters functions

Post Reply
micdj
Posts: 11
Joined: Wed Jan 06, 2021 2:23 am

Hello! I hope you someone can help me to transfer in new library all the functions i used before.

For example, if I want know the rolleshutter is in movement, before was:

Code: Select all

if (SuplaDevice.rollerShutterMotorIsOn(0))
and now?

I tr to understand class definiitons and i think is

Code: Select all

if (Supla::Control::RollerShutter::inMove())
but doensn't work

thank you to someone can help me
User avatar
klew
Posts: 8184
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

micdj wrote: Sun Jan 22, 2023 1:44 pm and now?
inMove is a protected method, so it can be called only by class methods.
You can use getCurrentDirection() method which is public. It returns:
0 - STOP
1 - DOWN
2 - UP

This method can be called only on an instance of a RollerShutter class (or on a pointer pointing on that instance).
You can store pointer to a roller shutter instance and then use it, i.e.:

Code: Select all

// global definition
Supla::Control::RollerShutter *rs1;

// in setup
rs1 = new Supla::Control::RollerShutter(....);

// in setup or in loop methods:
if (rs1->getCurrentDirection() != 0) {
  // in move
} else {
  // stop
}
Widzimy się na Supla Offline Party vol. 2 :!:
micdj
Posts: 11
Joined: Wed Jan 06, 2021 2:23 am

thank you for aswer, and how to implement thif old funcitons?

Code: Select all

SuplaDevice.setStatusFuncImpl(&status_func);
  SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
  SuplaDevice.setName(nomechar);
User avatar
klew
Posts: 8184
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

micdj wrote: Tue Feb 21, 2023 5:47 pm thank you for aswer, and how to implement thif old funcitons?

Code: Select all

SuplaDevice.setStatusFuncImpl(&status_func);
  SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
  SuplaDevice.setName(nomechar);
setStatusFuncImpl was left as it was in older version.
setName also.

Saving and restoring roller shutter position is handled in Supla::Storage classes. You can check RollerShutter example in SuplaDevice, here is relevant part of code:

Code: Select all

// Choose where Supla should store roller shutter data in persistant memory
// We recommend to use external FRAM memory 
#define STORAGE_OFFSET 100
#include <supla/storage/eeprom.h>
Supla::Eeprom eeprom(STORAGE_OFFSET);
// #include <supla/storage/fram_spi.h>
// Supla::FramSpi fram(STORAGE_OFFSET);
You can adjust storage offset to other value if you use "eeprom" class in your sketch.
Widzimy się na Supla Offline Party vol. 2 :!:
micdj
Posts: 11
Joined: Wed Jan 06, 2021 2:23 am

yes I know that now rollershutters uses storage class, but for obviously reason, in old library i used setStatusFuncImpl to save in FS position and close/open time.

I see in public class this functions that I see are for position and open/close time

Code: Select all

void onLoadState() override;
  void onSaveState() override;
Can I use them? How? Can you explain me please?
User avatar
klew
Posts: 8184
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

micdj wrote: Thu Feb 23, 2023 4:50 pm yes I know that now rollershutters uses storage class, but for obviously reason, in old library i used setStatusFuncImpl to save in FS position and close/open time.

I see in public class this functions that I see are for position and open/close time

Code: Select all

void onLoadState() override;
  void onSaveState() override;
Can I use them? How? Can you explain me please?
"setStatusFuncImpl" is a callback executed when device status changes, i.e. to "registered" or "disconnected" state. I'm not sure how and why you would like to use it for storing roller shutter open/close time.

RollerShutter use "onLoadState" and "onSaveState" methods to load and save their state, like: position, close/open time. They are called automatically, when Storage class instance is configured. However I don't recommend to use them for any custom storage, because they are part of procedures used in Supla::Storage class. I.e. during startup onSaveState is called before onLoadState - it is called "dry run" without actual write to storage, but it is used to calculate storage section size.

It will be easier to help if you share some more details on what and how you want to do, or if you share your "old code".
Widzimy się na Supla Offline Party vol. 2 :!:
micdj
Posts: 11
Joined: Wed Jan 06, 2021 2:23 am

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.
User avatar
klew
Posts: 8184
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

micdj wrote: Sun Feb 26, 2023 1:42 pm 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
I just added to library getters for closing and opening time. I think that easiest way to get data from roller shutter instance is to read those values from object.

I.e.

Code: Select all

Supla::Control::RollerShutter *rs1 = nullptr;

// in setup
rs1 = new RollerShutter(....);

// in loop
uint32_t closingTime = rs1->getClosingTimeMs();
uint32_t openingTime = rs1->getOpeningTimeMs();
// do_something_with(closingTime, openingTime);
auto pos = rs1->getCurrentPosition();
For "status" I already wrote that this method was left as it was in older library, so you can use it in the same way.
Widzimy się na Supla Offline Party vol. 2 :!:
micdj
Posts: 11
Joined: Wed Jan 06, 2021 2:23 am

Great!!! Thank you for your fast mod!!
I Will try next days to upgrade my code.
radzik_r
Posts: 390
Joined: Sun Aug 11, 2019 5:32 pm

klew wrote: Mon Jan 23, 2023 11:00 am
micdj wrote: Sun Jan 22, 2023 1:44 pm and now?
inMove is a protected method, so it can be called only by class methods.
You can use getCurrentDirection() method which is public. It returns:
0 - STOP
1 - DOWN
2 - UP

This method can be called only on an instance of a RollerShutter class (or on a pointer pointing on that instance).
You can store pointer to a roller shutter instance and then use it, i.e.:

Code: Select all

// global definition
Supla::Control::RollerShutter *rs1;

// in setup
rs1 = new Supla::Control::RollerShutter(....);

// in setup or in loop methods:
if (rs1->getCurrentDirection() != 0) {
  // in move
} else {
  // stop
}

I use for 12 blinds with my TFT like this

Code: Select all

int aktualny_ruch_rolety_[12] = { -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2};

for (int i = 0; i < 12; i++) {

  if (aktualny_ruch_rolety_[i] != ROLLER_SHUTTER_[i]->getCurrentDirection()) {
    aktualny_ruch_rolety_[i] = ROLLER_SHUTTER_[i]->getCurrentDirection();

    tft.setCursor(kolumna2, wiersz_[i]);
    tft.setTextColor(ST7735_ORANGE, ST7735_BLACK);
    switch (ROLLER_SHUTTER_[i]->getCurrentDirection()) {
      case 0: tft.print("STOP     "); break;
      case 1: tft.print("DOWN     "); break;
      case 2: tft.print(" UP      "); break;
    }
  }
}
Post Reply

Return to “Help”