77
88extern Preferences pref;
99
10- #define SHADE_HDR_VER 21
10+ #define SHADE_HDR_VER 22
1111#define SHADE_HDR_SIZE 76
1212#define SHADE_REC_SIZE 276
1313#define GROUP_REC_SIZE 194
@@ -554,6 +554,9 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
554554 }
555555 }
556556 }
557+ else {
558+ this ->file .seek (this ->file .position () + this ->header .repeaterRecordSize , SeekSet);
559+ }
557560 if (opts.settings ) {
558561 // First read out the data.
559562 this ->readSettingsRecord ();
@@ -584,6 +587,7 @@ bool ShadeConfigFile::restoreFile(SomfyShadeController *s, const char *filename,
584587}
585588bool ShadeConfigFile::readNetRecord () {
586589 if (this ->header .netRecordSize > 0 ) {
590+ uint32_t startPos = this ->file .position ();
587591 Serial.println (" Reading network settings from file..." );
588592 settings.connType = static_cast <conn_types>(this ->readUInt8 (static_cast <uint8_t >(conn_types::unset)));
589593 settings.IP .dhcp = this ->readBool (true );
@@ -598,9 +602,18 @@ bool ShadeConfigFile::readNetRecord() {
598602 settings.IP .dns1 .fromString (ip);
599603 this ->readVarString (ip, sizeof (ip));
600604 settings.IP .dns2 .fromString (ip);
605+ if (this ->header .version >= 22 ) {
606+ this ->readVarString (settings.MQTT .protocol , sizeof (settings.MQTT .protocol ));
607+ this ->readVarString (settings.MQTT .hostname , sizeof (settings.MQTT .hostname ));
608+ settings.MQTT .port = this ->readUInt16 (1883 );
609+ settings.MQTT .pubDisco = this ->readBool (false );
610+ this ->readVarString (settings.MQTT .rootTopic , sizeof (settings.MQTT .rootTopic ));
611+ this ->readVarString (settings.MQTT .discoTopic , sizeof (settings.MQTT .discoTopic ));
612+ }
601613 // Now lets check to see if we are the same board. If we are then we will restore
602614 // the ethernet phy settings.
603615 if (strncmp (settings.serverId , this ->header .serverId , sizeof (settings.serverId )) == 0 ) {
616+ Serial.println (" Restoring Ethernet adapter settings" );
604617 settings.Ethernet .boardType = this ->readUInt8 (1 );
605618 settings.Ethernet .phyType = static_cast <eth_phy_type_t >(this ->readUInt8 (0 ));
606619 settings.Ethernet .CLKMode = static_cast <eth_clock_mode_t >(this ->readUInt8 (0 ));
@@ -609,16 +622,16 @@ bool ShadeConfigFile::readNetRecord() {
609622 settings.Ethernet .MDCPin = this ->readInt8 (16 );
610623 settings.Ethernet .MDIOPin = this ->readInt8 (23 );
611624 }
612- else {
613- // We are not going to get the network adapter settings.
614- Serial.println (" Skipping Ethernet adapter settings (Chip ids do not match)..." );
625+ if (this ->file .position () != startPos + this ->header .netRecordSize ) {
626+ Serial.println (" Reading to end of network record" );
615627 this ->seekChar (CFG_REC_END);
616628 }
617629 }
618630 return true ;
619631}
620632bool ShadeConfigFile::readTransRecord (transceiver_config_t &cfg) {
621633 if (this ->header .transRecordSize > 0 ) {
634+ uint32_t startPos = this ->file .position ();
622635 Serial.println (" Reading Transceiver settings from file..." );
623636 cfg.enabled = this ->readBool (false );
624637 cfg.proto = static_cast <radio_proto>(this ->readUInt8 (0 ));
@@ -633,6 +646,11 @@ bool ShadeConfigFile::readTransRecord(transceiver_config_t &cfg) {
633646 cfg.rxBandwidth = this ->readFloat (cfg.rxBandwidth );
634647 cfg.deviation = this ->readFloat (cfg.deviation );
635648 cfg.txPower = this ->readInt8 (cfg.txPower );
649+ if (this ->file .position () != startPos + this ->header .transRecordSize ) {
650+ Serial.println (" Reading to end of transceiver record" );
651+ this ->seekChar (CFG_REC_END);
652+ }
653+
636654 }
637655 return true ;
638656}
@@ -947,6 +965,12 @@ bool ShadeConfigFile::writeNetRecord() {
947965 this ->writeVarString (settings.IP .subnet .toString ().c_str ());
948966 this ->writeVarString (settings.IP .dns1 .toString ().c_str ());
949967 this ->writeVarString (settings.IP .dns2 .toString ().c_str ());
968+ this ->writeVarString (settings.MQTT .protocol );
969+ this ->writeVarString (settings.MQTT .hostname );
970+ this ->writeUInt16 (settings.MQTT .port );
971+ this ->writeBool (settings.MQTT .pubDisco );
972+ this ->writeVarString (settings.MQTT .rootTopic );
973+ this ->writeVarString (settings.MQTT .discoTopic );
950974 this ->writeUInt8 (settings.Ethernet .boardType );
951975 this ->writeUInt8 (static_cast <uint8_t >(settings.Ethernet .phyType ));
952976 this ->writeUInt8 (static_cast <uint8_t >(settings.Ethernet .CLKMode ));
0 commit comments