Arduino Mega i pamięć FRAM

Maniek913
Posts: 160
Joined: Thu Feb 22, 2018 9:46 pm

Tue Apr 23, 2019 12:23 pm

Lesik wrote:
Sat Dec 01, 2018 9:44 am
Miałem podgrzane złe biblioteki. Teraz po restarcie pokazuje te same komunikaty ale tylko do czasu połączenia z serwerem. Po połączeniu i podczas podnoszenia rolety pokazuje „value changed”. Wykonałem kalibrację ale wyłączeniu zasilania i włączeniu nie pamięta ustawień. Pokazuje żeby wykonać kalibrację. Czy to może być błąd na ios? Czy komuś to działa poprawnie?
Podłączam się do pytania -Czy komuś działa zapis w fram? Z zapisu z konsoli wynika że pamieć fram jest wykrywana , ale nie pamięta ustawień , jak można sprawdzić czy rzeczywiście jest tam coś zapisywane?

14:14:43.005 -> Found SPI FRAM
14:14:43.005 -> Ethernet starts with MAC only
14:14:47.871 -> Ethernet configured
14:14:47.871 -> localIP: 192.168.2.2
14:14:47.918 -> subnetMask: 255.255.255.0
14:14:47.918 -> gatewayIP: 192.168.2.1
14:14:47.918 -> dnsServerIP: 192.168.2.1
14:14:47.972 -> SuplaDevice initialized
14:14:48.018 -> Not connected
14:14:48.072 -> Register in progress
14:15:18.100 -> Not connected
14:15:18.200 -> Register in progress
14:15:48.236 -> Not connected
14:15:48.336 -> Register in progress
14:15:48.336 -> Registered and ready.

Code: Select all

/*
  Copyright (C) AC SOFTWARE SP. Z O.O.
  
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_FRAM_SPI.h>
#include <SuplaDevice.h>

char tag[6] = {'S','U','P','L','A','1'};

typedef struct
{
  char tag[6];
  int position;
  unsigned int full_opening_time;
  unsigned int full_closing_time;
}RS_Settings;

RS_Settings settings;

bool FRAM_FOUND = false;
 
uint8_t FRAM_CS = 53;
uint8_t FRAM_SCK = 52;
uint8_t FRAM_MISO = 50;
uint8_t FRAM_MOSI = 51;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);

void settings_init(RS_Settings *settings) {
  memset(settings, 0, sizeof(RS_Settings));
  memcpy(settings->tag, tag, 6);
}

bool fram_read(int channelNumber) {
    memset(&settings, 0, sizeof(RS_Settings));
      
    if ( FRAM_FOUND )
      {
         fram.read (sizeof(RS_Settings)*channelNumber, (uint8_t *)&settings, sizeof(RS_Settings));
         if ( memcmp(&settings.tag, tag, 6) == 0 ) 
           {
              return true;         
           }
      }

      settings_init(&settings);

return false;
}

void fram_write(int channelNumber) {
      if ( FRAM_FOUND )
      {
         fram.writeEnable(true);
         fram.write (sizeof(RS_Settings)*channelNumber, (uint8_t *)&settings, sizeof(RS_Settings));
         fram.writeEnable(false);
      }
}

void supla_rs_SavePosition(int channelNumber, int position) {
  fram_read(channelNumber);
  settings.position = position;
  fram_write(channelNumber);
}

void supla_rs_LoadPosition(int channelNumber, int *position) {
  if ( fram_read(channelNumber) )
    {
       *position = settings.position;
    }
}

void supla_rs_SaveSettings(int channelNumber, unsigned int full_opening_time, unsigned int full_closing_time) {
  fram_read(channelNumber);
  settings.full_opening_time = full_opening_time;
  settings.full_closing_time = full_closing_time;
  fram_write(channelNumber);
}

void supla_rs_LoadSettings(int channelNumber, unsigned int *full_opening_time, unsigned int *full_closing_time) {
    if ( fram_read(channelNumber) )
    {
       *full_opening_time = settings.full_opening_time;
       *full_closing_time = settings.full_closing_time;
    }
}

void setup() {

  Serial.begin(9600);

  if (fram.begin()) {
    Serial.println("Found SPI FRAM");
    FRAM_FOUND = true;
  } else {
    Serial.println("No SPI FRAM found ... check your connections\r\n");
  }
 
  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {....................Guid...........................};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid


  // Ethernet MAC address
  uint8_t mac[6] = {0x03, 0x01, 0x02, 0x03, 0x04, 0x05};


  /*
   * Having your device already registered at cloud.supla.org,
   * you want to change CHANNEL sequence or remove any of them,
   * then you must also remove the device itself from cloud.supla.org.
   * Otherwise you will get "Channel conflict!" error.
   */
    

  // CHANNEL0 - TWO RELAYS (Roller shutter operation)
  SuplaDevice.addRollerShutterRelays(22,23);
  SuplaDevice.setRollerShutterButtons(0,11,12);
  
  SuplaDevice.addRollerShutterRelays(24,25);
  SuplaDevice.setRollerShutterButtons(1,8,9);
  
  SuplaDevice.addRollerShutterRelays(26,27);
  SuplaDevice.setRollerShutterButtons(2,6,7);
  
  SuplaDevice.addRollerShutterRelays(28,29);
  SuplaDevice.setRollerShutterButtons(3,3,5);
  
  SuplaDevice.addRollerShutterRelays(30,31);
  SuplaDevice.setRollerShutterButtons(4,14,2);
  
  SuplaDevice.addRollerShutterRelays(32,33);
  SuplaDevice.setRollerShutterButtons(5,16,15);
  
  SuplaDevice.addRollerShutterRelays(34,35);
  SuplaDevice.setRollerShutterButtons(6,18,17);
  
  SuplaDevice.addRollerShutterRelays(36,37);
  SuplaDevice.setRollerShutterButtons(7,20,19);
  
  SuplaDevice.addRollerShutterRelays(38,39);
  SuplaDevice.setRollerShutterButtons(8,A15,A2);
  
  SuplaDevice.addRollerShutterRelays(40,41);
  SuplaDevice.setRollerShutterButtons(9,A13,A14);
  
  SuplaDevice.addRollerShutterRelays(42,43);
  SuplaDevice.setRollerShutterButtons(10,A11,A12);
  
  SuplaDevice.addRollerShutterRelays(44,45);
  SuplaDevice.setRollerShutterButtons(11,A9,A10);
  
  SuplaDevice.addRollerShutterRelays(46,47);
  SuplaDevice.setRollerShutterButtons(12,A7,A8);
  
  SuplaDevice.addRollerShutterRelays(48,49);
  SuplaDevice.setRollerShutterButtons(13,A5,A6);
  
  SuplaDevice.addRollerShutterRelays(4,21);
  SuplaDevice.setRollerShutterButtons(14,A3,A4);

  
  SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
  
  /*
   * SuplaDevice Initialization.
   * Server address, LocationID and LocationPassword are available at https://cloud.supla.org 
   * If you do not have an account, you can create it at https://cloud.supla.org/account/create
   * SUPLA and SUPLA CLOUD are free of charge
   * 
   */
 
  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svrx.supla.org",  // SUPLA server address
                    xxxx,                // Location ID 
                    "xxxx");           // Location Password
    
}

void loop() {
  SuplaDevice.iterate();
}
User avatar
pzygmunt
Posts: 7035
Joined: Tue Jan 19, 2016 9:26 am
Location: Paczków
Contact:

Tue Apr 23, 2019 1:08 pm

Użyj biblioteki z GitHub-a. Zapis pozycji rolety do FRAM był poprawiany 3-go stycznia
https://github.com/SUPLA/arduino/commit ... 053732cd44
Maniek913
Posts: 160
Joined: Thu Feb 22, 2018 9:46 pm

Tue Apr 23, 2019 3:49 pm

Użyłem właśnie tej biblioteki do kompilacji - sprawdzałem nawet czy przytoczone wyżej linie kodu(315) są w mojej, aktualnie używanej bibliotece są zmienione , ale niestety nic to nie zmienia.
emil_seba
Posts: 16
Joined: Tue Apr 24, 2018 6:21 am

Thu Jun 13, 2019 6:59 am

hej,
Mi również nie udało się uruchomić supli z prawidłowa obsługa FRAM. Zrobiłem pewne testy i tak:

1. Do funkcji fram_write(int channelNumber) dodałem odczytanie struktury settings zaraz po jej zapisaniu.
2. Odczytuje te dane do drugiej struktury settingsSeba
3. porównując zawartość właściwości tag dla struktury settingsSeba i zmiennej tag dostaję wynik negatywny tzn. dane są inne.

Można by rzec, że problem jest z obsługą FRAM, ale tworzę nowy szkic, do którego wrzucam podobnie jak w supli utworzenie 2 struktur, ustawienie struktury settings zgodnie z funkcją settigns_init, zapisem tej struktury do FRAM, odczytanie danych z FRAM do struktury settingsSeba i dane są tożsame z właściwością tag.

Co robię źle ?

Szkic, którym weryfikowałem prawidłowość działania FRAM:

Code: Select all

#include <SPI.h>
#include "Adafruit_FRAM_SPI.h"

/* Example code to interrogate Adafruit SPI FRAM breakout for address size and storage capacity */

/* NOTE: This sketch will overwrite data already on the FRAM breakout */

uint8_t FRAM_CS = 53;
//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI();  // use hardware SPI

uint8_t FRAM_SCK = 52;
uint8_t FRAM_MISO = 50;
uint8_t FRAM_MOSI = 51;
//Or use software SPI, any pins!
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);

uint8_t           addrSizeInBytes = 2; //Default to address size of two bytes
uint32_t          memSize;
char tag[6] = {'S','U','P','L','A','1'};
typedef struct
{
  char tag[6];
  int position;
  unsigned int full_opening_time;
  unsigned int full_closing_time;
}RS_Settings;


RS_Settings settings;
RS_Settings settingsSeba;

void settings_init(RS_Settings *settings) {
  memset(settings, 0, sizeof(RS_Settings));
  memcpy(settings->tag, tag, 6);
}

void setup(void) {
  #ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif

  Serial.begin(9600);
  
  if (fram.begin(addrSizeInBytes)) {
    Serial.println("Found SPI FRAM");
  } else {
    Serial.println("No SPI FRAM found ... check your connections\r\n");
    while (1);
  }
  int channelNumber = 0;
  settings_init(&settings);
  fram.writeEnable(true);
  fram.write(sizeof(RS_Settings)*channelNumber, (uint8_t *)&settings, sizeof(RS_Settings));
  fram.writeEnable(false);
  fram.read(sizeof(RS_Settings)*channelNumber, (uint8_t *)&settingsSeba, sizeof(RS_Settings));
   if ( memcmp(&settingsSeba.tag, tag, 6) == 0 ) 
           {
               Serial.println("Dane sa takie same");
           }
           else
           {
              Serial.println("Dane sa rozne");
           }
  
}

void loop(void) {

}

Szkic Supli:

Code: Select all

#include <SPI.h>
#include <Ethernet.h>
#include <SuplaDevice.h>
#include <Adafruit_FRAM_SPI.h>

/*
  POZOR !!! dla ARDUINO 2 zmienic pin 13
  ############################################################################################################# 
     *  #              ARDUINO 1                        ###                      ARDUINO 2                          #
     *  #############################################################################################################     
     *  |pin in| pin przekaznika| co                    | |     |pin in| pin przekaznika| co                        |
     *  |0     |         |                              | |     |0     |          |                                 |
     *  |1     |         |                              | |     |1     |          |                                 |      
     *  |2     | A8 [62] |Roleta salon taras up         | |     |2     | A8  [62] |Roleta kuchnia up                |     
     *  |3     | A9 [63] |Roleta salon taras down       | |     |3     | A9  [63] |Roleta kuchnia down              |     
     *  |4     |         |Ethernet shield               | |     |4     |          |Ethernet shield                  |     
     *  |5     | A2 [56] |Roleta Sypialnia up           | |     |5     | A2  [56] |Roleta duza lazienka up          |     
     *  |6     | A3 [57] |Roleta Sypialnia down         | |     |6     | A3  [57] |Roleta duza lazienka down        |     
     *  |7     | A4 [58] |Roleta maly pokoj up          | |     |7     | A4  [58] |Roleta duzy pokoj 1 up           |     
     *  |8     | A5 [59] |Roleta maly pokoj down        | |     |8     | A5  [59] |Roleta duzy pokoj 1 down         |     
     *  |9     | A6 [60] |Roleta duzy pokoj 2 up        | |     |9     | A6  [60] |Roleta garaz up                  |     
	   *  |10    |         |Ethernet shield               | |     |10    |          |Ethernet shield                  |     
     *  |11    | A7 [61] |Roleta duzy pokoj 2 down      | |     |11    | A7  [61] |Roleta garaz down                |     
     *  |-----------------------------------------------------------------------------------------------------------|     
     *  |12    | 33      |sw salon stol 1               | |     |12    | A10 [64] |Roleta salon duże okno up        |
     *  |13    |         |Ethernet shield               | |     |13    | A11 [65] |Roleta salon duże okno down      |
     *  |14    | 35      |sw salon tv                   | |     |14    | 35       |sw salon stol 2                  |
     *  |15    | 36      |sw altana                     | |     |15    | 36       |sw taras lampki                  |
     *  |16    | 37      |sw kuchnia wyspa zewnetrzne   | |     |16    | 37       |sw salon tv 1                    |
     *  |17    | 38      |sw spizarnia                  | |     |17    | 38       |sw w korytarzu przy altanie      |
     *  |18    | 39      |sw mala lazienka              | |     |18    | 39       |sw maly pokoj                    |
     *  |19    | 40      |sw korytarz przy pokojach     | |     |19    | 40       |sw duzy pokoj                    |
     *  |-----------------------------------------------------------------------------------------------------------| 
     *  |20    | 41      |św przed garażem              | |     |20    | 41       |sw kuchnia wyspa srodek          |
     *  |21    | 42      |sw Garderoba                  | |     |21    | 42       |sw kuchnia przy tylnej scianie   |
     *  |22    | 43      |sw duza lazienka 1            | |     |22    | 43       |sw strych                        |
     *  |23    | 44      |sw kotłownia                  | |     |23    | 44       |sw skrytka (szafa)               |
     *  |24    | 45      |sw Garaz                      | |     |24    | 45       |sw przy drzwiach na dworze       |
     *  |25    | 46      |sw w podbitce                 | |     |25    | 46       |św sypialnia                     |
     *  |26    |         |brama wjazdowa up             | |     |26    | 47       |sw duza lazienka 2               |
     *  |27    |         |brama wjazdowa down           | |     |27    | 48       |sw warsztat                      |
     *  |-----------------------------------------------------------------------------------------------------------| 
     *  |28    |         |sw all                        | |     |28    |          |sw all                           |
     *  |29    |         |Roleta all up                 | |     |29    |          |Roleta all up                    |
     *  |30    |         |Roleta all down               | |     |30    |          |Roleta all down                  |
     *  |31    | 47      |Pompa wodt                    | |     |31    |          |Brama garazowa up                |
     *  |32    | 34      |sw taras                      | |     |32    |          |Brama garazowa down              |
     *  |0     |         |                              | |     |0     |          |                                 |
        |######|#########|##############################|#|#####|######|##########|#################################|
*/

#define BTN_COUNT 17  // definiujemy ile ma być przycisków 

#define MY_DEBUG


//***********button*****************//
 typedef struct {
  int pin;
  int relay_pin;
  int channel;
  int ms;
  char last_val;
  unsigned long last_time;
  String nazwa;
  unsigned int channelgroup[];
} _btn_t;

_btn_t btn[BTN_COUNT];

char tag[6] = {'S','U','P','L','A','1'};

typedef struct
{
  char tag[6];
  int position;
  unsigned int full_opening_time;
  unsigned int full_closing_time;
}RS_Settings;

RS_Settings settings;
RS_Settings settingsSeba;

bool FRAM_FOUND = false;

uint8_t FRAM_CS = 53;
uint8_t FRAM_SCK= 52;
uint8_t FRAM_MISO = 50;
uint8_t FRAM_MOSI = 51;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS);


void supla_timer() {
  char v;
  unsigned long now = millis();
  for(int a=0;a<BTN_COUNT;a++) {
    if (btn[a].pin > 0) {
        v = digitalRead(btn[a].pin);
        if (v != btn[a].last_val && now - btn[a].last_time ) {
         
           btn[a].last_val = v;
           btn[a].last_time = now;
           if (v==0)
            {
               #ifdef MY_DEBUG
                  Serial.println("Wcisnieto pin nr: [" + String(btn[a].pin) + "] odpowiedzialny za: " + String(btn[a].nazwa));
               #endif
                //obsługa grup
                if(btn[a].relay_pin > 99){
                    Serial.println("Obsługa grup");
                    if(btn[a].pin == 29){
                      //up
                      Serial.println("Otwieram rolety");
                      if(digitalRead(62) > 0 ){
                        SuplaDevice.rollerShutterStop(0);
                      }
                      else{ SuplaDevice.rollerShutterReveal(0); }

                      if(digitalRead(56) > 0 ){
                        SuplaDevice.rollerShutterStop(1);
                      }
                      else{ SuplaDevice.rollerShutterReveal(1); }
                    }
                    if(btn[a].pin == 30){
                      //down
                      Serial.println("Zamykam Rolety");
                       if(digitalRead(63) > 0 ){
                        SuplaDevice.rollerShutterStop(0);
                      }
                      else{ SuplaDevice.rollerShutterShut(0); }
                       if(digitalRead(57) > 0 ){
                        SuplaDevice.rollerShutterStop(1);
                      }
                      else{ SuplaDevice.rollerShutterShut(1); }
                 
                    }
                }
                else {
                  if ( btn[a].ms > 0 ) {
                      #ifdef MY_DEBUG
                        Serial.println("Wlaczam przekaznik na czas " + String(btn[a].ms));
                      #endif
                      SuplaDevice.relayOn(btn[a].channel, btn[a].ms);
                  } 
                  else if (digitalRead(btn[a].relay_pin) > 0 ) {
                        #ifdef MY_DEBUG
                          Serial.println("Wylaczam przekaznik: " + String(btn[a].relay_pin));
                        #endif
                        SuplaDevice.relayOff(btn[a].channel);
                      
                  } 
                  else {
                        #ifdef MY_DEBUG
                          Serial.println("Wlaczam przekaznik: " + String(btn[a].relay_pin) + " na kanale: " + btn[a].channel);
                        #endif
                        SuplaDevice.relayOn(btn[a].channel, 0);
                  } 
                }   
            }
        }
    }
  }
}


void settings_init(RS_Settings *settings) {
  memset(settings, 0, sizeof(RS_Settings));
  memcpy(settings->tag, tag, 6);
}

bool fram_read(int channelNumber) {
    memset(&settings, 0, sizeof(RS_Settings));
      
    if ( FRAM_FOUND )
      {
         fram.read (sizeof(RS_Settings)*channelNumber, (uint8_t *)&settings, sizeof(RS_Settings));
         if ( memcmp(&settings.tag, tag, 6) == 0 ) 
           {
              return true;         
           }
      }

      settings_init(&settings);

return false;
}

void fram_write(int channelNumber) {
      if ( FRAM_FOUND )
      {
        Serial.println("[fram_write] for channe; " + String(channelNumber));

         fram.writeEnable(true);
         fram.write (sizeof(RS_Settings)*channelNumber, (uint8_t *)&settings, sizeof(RS_Settings));
         fram.writeEnable(false);

        fram.read (sizeof(RS_Settings)*channelNumber, (uint8_t *)&settingsSeba, sizeof(RS_Settings));
         if ( memcmp(&settingsSeba.tag, tag, 6) == 0 ) 
           {
               Serial.println("Struktura settingsSeba == tag");
           }
           else
           {
              Serial.println("Struktura settingsSeba jest != od tag");
           }
           
      }
}
 
void supla_rs_SavePosition(int channelNumber, int position) {
  Serial.println("[supla_rs_SavePosition] on channel " + String(channelNumber) + " to " + String(position));
  fram_read(channelNumber);
  settings.position = position;
  fram_write(channelNumber);
}

void supla_rs_LoadPosition(int channelNumber, int *position) {
  Serial.println("[supla_rs_LoadPosition] on channel " + String(channelNumber) + " to " + String(settings.position));
  if ( fram_read(channelNumber) )
    {
       Serial.println("[supla_rs_LoadPosition -> fram_read_ok] on channel " + String(channelNumber) + " to " + String(settings.position));
       *position = settings.position;
    }
}

void supla_rs_SaveSettings(int channelNumber, unsigned int full_opening_time, unsigned int full_closing_time) {
  fram_read(channelNumber);
  settings.full_opening_time = full_opening_time;
  settings.full_closing_time = full_closing_time;
  fram_write(channelNumber);
}

void supla_rs_LoadSettings(int channelNumber, unsigned int *full_opening_time, unsigned int *full_closing_time) {
    if ( fram_read(channelNumber) )
    {
       *full_opening_time = settings.full_opening_time;
       *full_closing_time = settings.full_closing_time;
    }
}



void supla_btn_init() {
  #ifdef MY_DEBUG 
    Serial.println("Enter supla_btn_init");
  #endif
  for(int a=0;a<BTN_COUNT;a++)
  {
    if (btn[a].pin > 0) {
        pinMode(btn[a].pin, INPUT_PULLUP); 
        btn[a].last_val = digitalRead(btn[a].pin);
        btn[a].last_time = millis();
    }
  }
     //show_my_btn();
}

void show_my_btn()
{ 
  for(int i=0; i<BTN_COUNT; i++)
  {
      Serial.println("Btn nr " + String(i));
      Serial.println("btn pin: " + String(btn[i].pin));
      Serial.println("btn relay: " + String(btn[i].relay_pin));
      Serial.println("btn last val: " + String(btn[i].last_val));
      Serial.println("btn last time: " + String(btn[i].last_time));
      Serial.println("btn nazwa: " + String(btn[i].nazwa));
  }
}



void setMyButton()
{
  memset(btn, 0, sizeof(btn)); 
  // działa
  btn[0].pin = 12; //pin pod którym masz przycisk (wewnętrzny PULLUP)
  btn[0].relay_pin = 33; //pin pod który podłączony jest przekaźnik
  btn[0].channel = 4; //numer kanału na którym jest przekaźnik
  btn[0].ms = 0;  //jak zero to ma być cały czas włączony
  btn[0].nazwa = "swSalonStol1";
  SuplaDevice.addRelay(btn[0].relay_pin, false); 

  btn[1].pin = 32; 
  btn[1].relay_pin = 34;
  btn[1].channel = 5;
  btn[1].ms = 0; 
  btn[1].nazwa = "swTaras";
  SuplaDevice.addRelay(btn[1].relay_pin, false); 


  btn[2].pin = 14; 
  btn[2].relay_pin = 35;
  btn[2].channel = 6;
  btn[2].ms = 0; 
  btn[2].nazwa = "swSalonTV1";
  SuplaDevice.addRelay(btn[2].relay_pin, false); 


  btn[3].pin = 15; 
  btn[3].relay_pin = 36;
  btn[3].channel = 7;
  btn[3].ms = 0; 
  btn[3].nazwa = "swAltana";
  SuplaDevice.addRelay(btn[3].relay_pin, false); 


  btn[4].pin = 16; 
  btn[4].relay_pin = 37;
  btn[4].channel = 8;
  btn[4].ms = 0; 
  btn[4].nazwa = "swKuchania1";
  SuplaDevice.addRelay(btn[4].relay_pin, false); 


  btn[5].pin = 17; 
  btn[5].relay_pin = 38;
  btn[5].channel = 9;
  btn[5].ms = 0; 
  btn[5].nazwa = "swSpizarnia";
  SuplaDevice.addRelay(btn[5].relay_pin, false); 


  btn[6].pin = 18; 
  btn[6].relay_pin = 39;
  btn[6].channel = 10;
  btn[6].ms = 0; 
  btn[6].nazwa = "swMalaLazienka";
  SuplaDevice.addRelay(btn[6].relay_pin, false); 


  btn[7].pin = 19; 
  btn[7].relay_pin = 40;
  btn[7].channel = 11;
  btn[7].ms = 0; 
  btn[7].nazwa = "swKorytarzPokoje";
  SuplaDevice.addRelay(btn[7].relay_pin, false); 


  btn[8].pin = 20; 
  btn[8].relay_pin = 41;
  btn[8].channel = 12;
  btn[8].ms = 0; 
  btn[8].nazwa = "swPrzedGarazem";
  SuplaDevice.addRelay(btn[8].relay_pin, false); 

  
  btn[9].pin = 21; 
  btn[9].relay_pin = 42;
  btn[9].channel = 13;
  btn[9].ms = 0; 
  btn[9].nazwa = "swGarderoba";
  SuplaDevice.addRelay(btn[9].relay_pin, false); 


  btn[10].pin = 22; 
  btn[10].relay_pin = 43;
  btn[10].channel = 14;
  btn[10].ms = 0; 
  btn[10].nazwa = "swDuzaLazienka1";
  SuplaDevice.addRelay(btn[10].relay_pin, false); 


  btn[11].pin = 23; 
  btn[11].relay_pin = 44;
  btn[11].channel = 15;
  btn[11].ms = 0; 
  btn[11].nazwa = "swKotlownia";
  SuplaDevice.addRelay(btn[11].relay_pin, false); 


  btn[12].pin = 24; 
  btn[12].relay_pin = 45;
  btn[12].channel = 16;
  btn[12].ms = 0; 
  btn[12].nazwa = "swGaraz";
  SuplaDevice.addRelay(btn[12].relay_pin, false); 


  btn[13].pin = 25; 
  btn[13].relay_pin =46;
  btn[13].channel = 17;
  btn[13].ms = 0; 
  btn[13].nazwa = "swPodbitka";
  SuplaDevice.addRelay(btn[13].relay_pin, false); 


  btn[14].pin = 28; 
  btn[14].relay_pin = 100;
  btn[14].channel = 18;
  btn[14].ms = 0; 
  btn[14].nazwa = "swAll";
  //btn[14].channelgroup[4] = {{ 4, 7, 11}};

  btn[15].pin = 29; 
  btn[15].relay_pin = 101;
  btn[15].channel = 18;
  btn[15].ms = 0; 
  btn[15].nazwa = "roletyAllUp";
  //btn[15].channelgroup[4] = {{0, 1, 2, 3}};

  btn[16].pin = 30; 
  btn[16].relay_pin = 102;
  btn[16].channel = 18;
  btn[16].ms = 0; 
  btn[16].nazwa = "roletyAllDown";
  //btn[16].channelgroup[4] = {{0, 1, 2, 3}};


}
void setMyRoller()
{
  //Rolerta salon taras
  SuplaDevice.addRollerShutterRelays(62, 63);  // 62 - Pin number where the 1st relay is connected    63 - Pin number where the 2nd relay is connected                  
  SuplaDevice.setRollerShutterButtons(0, 2, 3);  // 0 - Channel Number // 20 - Pin where the 1st button is connected // 21 - Pin where the 2nd button is connected

  SuplaDevice.addRollerShutterRelays(56,57);   //Sypialnia
  SuplaDevice.setRollerShutterButtons(1, 5, 6); //Sypialnia

  SuplaDevice.addRollerShutterRelays(58,59);   //Maly pokoj
  SuplaDevice.setRollerShutterButtons(2, 7, 8); //Maly pokoj

  SuplaDevice.addRollerShutterRelays(60,61);   //Duzy pokoj
  SuplaDevice.setRollerShutterButtons(3, 9, 11); //Duzy pokoj
}

void setup() {

  Serial.begin(9600);
  setMyRoller();
  setMyButton();
  supla_btn_init();

  if (fram.begin()) {
    Serial.println("Found SPI FRAM");
    FRAM_FOUND = true;
  } else {
    Serial.println("No SPI FRAM found ... check your connections\r\n");
  }
 

  SuplaDevice.setTimerFuncImpl(&supla_timer);
  SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);

  
  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {xyz};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid


  // Ethernet MAC address
  uint8_t mac[6] = {xyz};

 
  // CHANNEL0 - RELAY
          // 44 - Pin number where the relay is connected      
                                      // Call SuplaDevice.addRelay(44, true) with an extra "true" parameter 
                                      // to enable "port value inversion"
                                      // where HIGH == LOW, and LOW == HIGH   

  // CHANNEL1 - RELAY
  //SuplaDevice.addRelay(45, true);           // 45 - Pin number where the relay is connected   


  /*
   * SuplaDevice Initialization.
   * Server address, LocationID and LocationPassword are available at https://cloud.supla.org 
   * If you do not have an account, you can create it at https://cloud.supla.org/account/create
   * SUPLA and SUPLA CLOUD are free of charge
   * 
   */

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "xxx",  // SUPLA server address
                    yyy,                 // Location ID 
                    "zzz");               // Location Password

}

void loop() {
  SuplaDevice.iterate();
}
emil_seba
Posts: 16
Joined: Tue Apr 24, 2018 6:21 am

Fri Aug 02, 2019 1:05 pm

ktoś z kolegów/koleżanek mógł by pomóc z powyższym ? Nie spotkałem na forum poprawnie działającego odczytu pamięci na arduino.
Maniek913
Posts: 160
Joined: Thu Feb 22, 2018 9:46 pm

Fri Aug 02, 2019 7:54 pm

Aby po restarcie wracały stany kanałów to trzeba rozbudować bibliotekę:
viewtopic.php?f=8&t=4717
Też czekam z niecierpliwością
Post Reply