Backing-up and restoring a new zwave.me chip with the C API

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
Tom_Tron
Posts: 6
Joined: 03 Feb 2017 03:33

Backing-up and restoring a new zwave.me chip with the C API

Post by Tom_Tron »

I have a problem, I’ve been trying to find a way to back-up and restore a zwave.me chip with a replacement chip using the Z-Way C library API. I Basically want to be able to replace a faulty chip without having to go through the arduous process of re-pairing all of the things to the new zwave.me chip when it is replaced. I have tried to do this with the example Z-Way C library API code as I do not wish to install the zway User interface The steps I have run through to achieve this are as follows

1: check the things and the zwave.me chip are paired correctly if they are I run the script with the zwave.me chip I want to back up using the test_save(zway); method provided in the Z-Way C library example code. This creates a .tgz file in the /tmp folder called z-way-test.tgz

2: I turn off the Pi and replace it with a new z-wave.me chip

3:When the pi is restarted I recompile the C file to run first run the restore to factory settings method zway_controller_set_default(zway); I then run the restore method test_restore(zway); .

4: when I check the items not longer seem paired but when I put the zwave.me chip .but when put in the original zwave.me chip from which I took the backup everything the original zwave.me chip and items are still paired correctly.

So is there a way to back up a zwave.me and restore it without having to put all of the items associated with are zwave.me chip in discovery mode and re-pair them? if so how can this be done with the Z-Way C library API code?

Note: I am using openhab2 on my pi which I am always careful to turn off when I run the Z-Way C library API scripts
Tom_Tron
Posts: 6
Joined: 03 Feb 2017 03:33

Re: Backing-up and restoring a new zwave.me chip with the C

Post by Tom_Tron »

I’ve Analysed this problem in a bit more detail now. The save method works fine when you run test_save() it backs up the chips current state into and xml file and stores it in config.tgz .but when you take out the old chip and put in a new chip run and the test_resore method the changes are not persisting through to the newly inserted z-wave.me chip. The method zway_controller_config_restore(zway, data, length, TRUE); which should make it a full restore. The restore seems to run fine but when I do a test_save() again to see if the changes have persisted correctly the xml in the config.tgz file looks like the old configuration on the replacement chip not the newly restored configuration hence the changes seem not to have persisted. Also when I checked the pairing in openhab2 they are broken further indicating that the changes have not persisted
I put some snippets of the code and that I am using below. If anyone has any Ideas of where I’m going wrong it would be much appreciated

test_restore

Code: Select all

void test_restore(ZWay zway)
{
    char path[MAX_PATH];
    strcpy(path, "/home/pi/config.tgz");
    
    printf("Reading config from %s\n", path);
    
    struct stat finfo;
    int tr = stat(path, &finfo);
    if (tr != 0)
    {
        if (errno == ENOENT)
        {
            printf("Config not found. Save one first!\n");
        }
        else
        {
            printf("Config read error: %s\n", strerror(errno));
        }
        return;
    }
    
    size_t length = finfo.st_size;
    ZWBYTE *data = (ZWBYTE*)malloc(length);
    if (data == NULL)
    {
        printf("Failed to alloc %zu bytes!\n", length);
        return;
    }
    printf("open file on path : %s\n", path);
    FILE *t = fopen(path, "rb");
	
    if (t != NULL)
    {
	    printf("read data\n");
		printf("the data: %s\n", data);
        fread(data, 1, length, t);
        fclose(t);
    }
    else
    {
        free(data);
        printf("Config read error: %s\n", strerror(errno));
        return;
    }
    
    ZWError r = zway_controller_config_restore(zway, data, length, TRUE);
    if (r == NoError)
    {
        printf("Configuration successfully restored\n");
    }
    else
    {
        printf("Error restoring configuration! (err = %s)\n", zstrerror(r));
    }
    
    free(data);
}
Test_Save

Code: Select all

void test_save(ZWay zway)
{
    ZWError r;
    
    ZWBYTE *data = NULL;
    size_t length = 0;
    r = zway_controller_config_save(zway, &data, &length);
    if (r == NoError)
    {
        printf("Successfully saved! (size = %lu)\n", (unsigned long int) length);
        
        char path[MAX_PATH];
        strcpy(path, "/home/pi/config.tgz");
        
        FILE *t = fopen(path, "wb");
        if (t != NULL)
        {
            fwrite(data, 1, length, t);
            fclose(t);
            
            printf("Config written to %s\n", path);
        }
        else
        {
            printf("Config write error: %s\n", strerror(errno));
        }
        
        free(data);
    }
    else
    {
        printf("Error saving configuration! (err = %s)\n", zstrerror(r));
    }
}
Output when running restore "test_restore(zway);

Code: Select all

Reading config from /home/pi/config.tgz
open file on path : /home/pi/config.tgz
read data
the data:
[2017-02-05 03:03:51.924] [D] RECEIVED: ( 01 09 01 41 93 96 01 02 02 01 B3 )
[2017-02-05 03:03:51.924] [D] SENT ACK
[2017-02-05 03:03:51.933] [D] SETDATA devices.1.data = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.dynamic = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.dynamic = False
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.genericType = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.genericType = 0 (0x00000000)
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.specificType = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.instances.0.data.specificType = 0 (0x00000000)
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.basicType = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.genericType = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.specificType = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.infoProtocolSpecific = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.deviceTypeString = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.isVirtual = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.isListening = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.isRouting = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.isAwake = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.optional = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.isFailed = Empty
[2017-02-05 03:03:51.934] [D] SETDATA devices.1.data.beam = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.sensor250 = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.sensor1000 = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.neighbours = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.manufacturerId = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.vendorString = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.manufacturerProductType = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.manufacturerProductId = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.ZWLib = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.ZWProtocolMajor = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.ZWProtocolMinor = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.SDK = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.applicationMajor = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.applicationMinor = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.nodeInfoFrame = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.ZDDXMLFile = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.lastSend = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.lastNonceGet = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.lastReceived = Empty
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.failureCount = Empty
[2017-02-05 03:03:51.935] [I] Restoring controller from ./config/zddx/d0163ef8-DevicesData.xml
[2017-02-05 03:03:51.935] [D] SETDATA devices.1.data.keepAwake = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.countSuccess = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.countFailed = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.queueLength = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.givenName = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.lastPacketInfo = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.lastPacketInfo.deliveryTime = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.lastPacketInfo.delivered = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.lastPacketInfo.packetLength = Empty
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.basicType = 0 (0x00000000)
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.genericType = 0 (0x00000000)
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.specificType = 0 (0x00000000)
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.infoProtocolSpecific = 0 (0x00000000)
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.deviceTypeString = ""
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.isVirtual = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.isListening = True
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.isRouting = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.isAwake = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.optional = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.isFailed = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.beam = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.sensor250 = False
[2017-02-05 03:03:51.936] [D] SETDATA devices.1.data.sensor1000 = False
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.neighbours = Empty
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.manufacturerId = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.manufacturerProductType = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.manufacturerProductId = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.applicationMajor = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.applicationMinor = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.ZWProtocolMajor = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.ZWProtocolMinor = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.ZWLib = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.SDK = ""
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.vendorString = ""
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.nodeInfoFrame = Empty
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.ZDDXMLFile = ""
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.keepAwake = False
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.countSuccess = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.countFailed = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.queueLength = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.lastReceived = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.lastSend = 0 (0x00000000)
[2017-02-05 03:03:51.937] [D] SETDATA devices.1.data.failureCount = 0 (0x00000000)
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.data.givenName = ""
[2017-02-05 03:03:51.938] [I] Adding job: Get node protocol information
[2017-02-05 03:03:51.938] [I] Adding job: Get routing table line
[2017-02-05 03:03:51.938] [I] New device added: 1
[2017-02-05 03:03:51.938] [D] Job 0x80 (Get routing table line): removing duplicate
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.data.basicType = 2 (0x00000002)
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.data.genericType = 2 (0x00000002)
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.instances.0.data.genericType = 2 (0x00000002)
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.data.specificType = 1 (0x00000001)
[2017-02-05 03:03:51.938] [D] SETDATA devices.1.instances.0.data.specificType = 1 (0x00000001)
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.deviceTypeString = "Static PC Controller"
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.isRouting = False
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.isListening = True
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.optional = True
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.sensor1000 = False
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.sensor250 = False
[2017-02-05 03:03:51.940] [D] SETDATA devices.1.data.infoProtocolSpecific = 9672193 (0x00939601)
[2017-02-05 03:03:51.940] [D] Job 0x41 (Get node protocol information): success
[2017-02-05 03:03:51.940] [I] Removing job: Get node protocol information
[2017-02-05 03:03:51.940] [D] SENDING: ( 01 1C 00 03 03 02 01 15 5E 86 60 8F 81 46 98 26 25 72 8A 2B 77 20 22 5B 56 73 85 59 5A C0 )
[2017-02-05 03:03:51.943] [D] RECEIVED ACK
[2017-02-05 03:03:51.943] [I] Removing job: Set controller node information frame
[2017-02-05 03:03:51.954] [D] SENDING: ( 01 03 00 05 F9 )
[2017-02-05 03:03:51.954] [D] RECEIVED ACK
[2017-02-05 03:03:51.964] [D] RECEIVED: ( 01 04 01 05 28 D7 )
[2017-02-05 03:03:51.964] [D] SENT ACK
[2017-02-05 03:03:51.964] [D] SETDATA controller.data.isPrimary = True
[2017-02-05 03:03:51.964] [D] SETDATA controller.data.isInOthersNetwork = False
[2017-02-05 03:03:51.964] [D] SETDATA controller.data.SISPresent = False
[2017-02-05 03:03:51.964] [D] SETDATA controller.data.isRealPrimary = True
[2017-02-05 03:03:51.964] [D] SETDATA controller.data.isSUC = False
[2017-02-05 03:03:51.964] [D] Job 0x05 (Get controller capabilities): success
[2017-02-05 03:03:51.964] [I] Adding job: Set new SUC/SIS
[2017-02-05 03:03:51.964] [I] Removing job: Get controller capabilities
[2017-02-05 03:03:51.964] [D] SENDING (cb 0x02): ( 01 04 00 42 02 BB )
[2017-02-05 03:03:51.965] [D] RECEIVED ACK
[2017-02-05 03:03:52.008] [I] Adding job: Reset the controller
[2017-02-05 03:03:52.008] [D] SETDATA controller.data.controllerState = 20 (0x00000014)
[2017-02-05 03:03:52.008] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.009] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.009] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.009] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.009] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.009] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.010] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.010] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.010] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.010] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.010] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.011] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.012] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.012] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.012] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.013] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.014] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.014] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.014] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.014] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.015] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.016] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.016] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.016] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.016] [I] Adding job: Write bytes to EEPROM
[2017-02-05 03:03:52.016] [I] Adding job: Get home id and controller node id
Configuration successfully restored
User avatar
PoltoS
Posts: 7579
Joined: 26 Jan 2011 19:36

Re: Backing-up and restoring a new zwave.me chip with the C

Post by PoltoS »

After doing Restore you should wait till it writes to the flash and reboots the chip. Basically the lib should do it itself.
Post Reply