Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. meddie
    3. Posts
    • Continue chat with meddie
    • Start new chat with meddie
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by meddie

    • RE: 💬 Sensebender Gateway

      @alexsh1
      hi, yes it was very simple 😄 the gateway has worked fine in this time, i thought that when nothing shown in serial monitor that the gateway dont work, but it did it, after i connected the gateway to FHEM (my controller) i saw that FHEM connects t mys Gateway.
      So it worked all the time

      Greets Eddie

      posted in OpenHardware.io
      meddie
    • Sensebender Micro Battery Code

      Hello together,

      i have bought a sensebender micro to test as temp and humidity sensor. I use the example sketch from sensebender, and for test i used a cd2032 battery but the battery is after 14 days empty.
      So i have to optimize my code and would like to ask you which settings are you using for battery nodes.

      How often do you transmit the temp / humidity?
      Which threshold for changing the temp / humidity?

      Thanks a lot
      Greets Eddie

      posted in Development
      meddie
    • RE: 💬 Sensebender Micro

      @Michiel-van-der-Wulp
      thank you i will test it the next few days

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Micro

      @Michiel-van-der-Wulp
      Can you tell me where in the code is the switch to 1 MHz? I still have the problems that my node dosnt send anymore. It works for several hours but after then it dont send anything.

      In programming i am not good, and so i cant find the switch.
      Thank you very much.
      Greets Eddie

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Micro

      @qqlapraline
      oh yes it does! It explains why i get the € signs in the serial monitor. But why does the node not send to my FHEM Controller? Depends it also on it, that the node switch to 1 Mhz and cant send anymore?
      Thank you very much for your answer, its very helpfull.
      Greets Eddie

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Micro

      i have just tried it again, it worked for 20 minutes. After them i get this output:

      Sensebender Micro FW 1.4 - Online!
      isMetric: 1
      TempDiff :122.28
      HumDiff  :154.00
      T: 22.28
      H: 54
      TempDiff :0.00
      HumDiff  :0.00
      TempDiff :0.10
      HumDiff  :0.50
      TempDiff :0.11
      HumDiff  :0.50
      TempDiff :0.12
      HumDiff  :0.00
      €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
      
      

      ok one more thing i found, when i close the serial monitor and start it again, i get the correctly output again, and i see in fhem the new readings.

      but i cant understand what happens why stop the node to transmit the correct readings

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Micro

      Hey together,

      i have an problem, i had some troubles with the space on the sb micro, i have removed the #define my_debug that solved my space problem, but now i have observed that the node is starting and sends few times the temp and humidity but after the few times nothing happens anymore.
      i observed, when i hold the sensor in the fingers so that it will be worm, and start the node then it sends all minute the temp, but when the temp goes down to the room temperature then the node should send only when the humidity or temp changes over the threshhold, so in the room i dont have much changes and i think that when the node does not send about a longer time, that the the problem comes up.
      I tested it in some different distances, on another floor but in very short distance too. I dont think that is a radio problem.
      What do you think about?
      The Problem is, that i cant debug the node because i disabled it because of space problems.
      Thank you

      posted in OpenHardware.io
      meddie
    • RE: [security] Introducing signing support to MySensors

      i observed, when i hold the sensor in the fingers so that it will be worm, and start the node then it sends all minute the temp, but when the temp goes donw to the room temperature the the node sends only when the humidity or temp changes over the threshhold, but in the room i dont have much changes and i think that when the node does not send about longer time, that the the problem comes up.
      I tested it in some different distances, on another floor but in very short distance too. I dont think that is a radio problem.
      What do you think about?
      The Problem is, that i cant debug the node because i disabled it because of space problems.
      Thank you

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      sorry i didnt let hear anything from me for the last few days.
      i had the same problems with compiling the sketch. It depends on the signing. When you remove the #define MY_SIGNING_ATSHA204 the you can compile but when the singning is defined you get an error until you remove this line:
      #include <drivers/ATSHA204/ATSHA204.cpp>

      i have removed the line and defined the signing and for me works the singing and encryption.

      but i have an another problem, i dont know if i am right here or i better have to post in the sensebender micro forum, i posted that i had some troubles with the space on the sb micro, i have removed the #define my_debug that solved my space problem, but now i have observed that the node is starting and sends few times the temp and humidity but after the few times nothing happens anymore.

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      i used the stable lib and comiled the sketch both features are now working encryption and signing! Thank you very much!!!!! I will try to update the example lib and try again.

      I got just the next problem the space from sensebender micro is not enought to use all three features signing, encryption and ota. When i use AES and Signing i get over 109%, when i use the example sketch temp and humidty meassure.

      Greets Eddie

      posted in Development
      meddie
    • RE: 💬 Sensebender Micro

      Hey together,
      i have a question, because i have some capacity troubles. I used the example sketch from sensebender micro that meassures the temperature and humidity but i have additional activated the signing and encryption and now i got over the availible space 109%.
      use anybody from you all the features? what i have to do?
      thank you

      posted in OpenHardware.io
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      its combined from two example sketches sensebendergateway and gatewayw5100 example sketch

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      Hi, i just tried it out and now it and it has worked! The Aes key is stored correctly! BUT i get now an error on compile the gateway sketch

      C:\Users\meddie\Documents\Arduino\SenseebnderGW_LAN_NRF24\SenseebnderGW_LAN_NRF24.ino\SenseebnderGW_LAN_NRF24.ino.ino: In function 'bool testEEProm()':
      
      SenseebnderGW_LAN_NRF24.ino:315: error: 'i2c_eeprom_read_byte' was not declared in this scope
      
         eeprom_d1 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
      
                                                                     ^
      
      SenseebnderGW_LAN_NRF24.ino:318: error: 'i2c_eeprom_write_byte' was not declared in this scope
      
         i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
      

      i could use the stable lib again then it should compile, but i think you would like to know that an error occours.
      Greets Eddie

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      thank you very much for your support and for your patience with me!!!!
      i just tried and the signing is working fine!!!!
      i look forward to try the encryption! i

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      and this is the serial output:

      This key will be stored in EEPROM as AES key:
      #define MY_AES_KEY 0x6A,0x2B,0xF7,0xFB,0x03,0x8D,0x03,0x85,0x4D,0xDA,0x2D,0x89,0x9F,0xAD,0x8B,0x4F
      EEPROM configuration:
      SOFT_HMAC_KEY | 01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      SOFT_SERIAL   | 10FFFFFFFFFFFFFFFF
      AES_KEY       | 6AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      --------------------------------
      Personalization is now complete.
      
      
      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      yes of course!!!
      here is the sketch:

      #include "sha204_library.h"
      #include "sha204_lib_return_codes.h"
      #define MY_CORE_ONLY
      #include <MySensors.h>
      
      // Doxygen specific constructs, not included when built normally
      // This is used to enable disabled macros/definitions to be included in the documentation as well.
      #if DOXYGEN
      #define LOCK_CONFIGURATION
      #define LOCK_DATA
      #define SKIP_KEY_STORAGE
      #define USER_KEY
      #define SKIP_UART_CONFIRMATION
      #define USE_SOFT_SIGNING
      #define STORE_SOFT_KEY
      #define USER_SOFT_KEY
      #define STORE_SOFT_SERIAL
      #define USER_SOFT_SERIAL
      #define STORE_AES_KEY
      #define USER_AES_KEY
      #endif
      
      #define LOCK_CONFIGURATION
      
      
      //#define LOCK_DATA
      
      
      //#define SKIP_KEY_STORAGE
      
      
      //#define USER_KEY
      
      
      //#define SKIP_UART_CONFIRMATION
      
      
      #define USE_SOFT_SIGNING
      
      
      #define STORE_SOFT_KEY
      
      
      #define USER_SOFT_KEY
      
      
      #define STORE_SOFT_SERIAL
      
      
      #define USER_SOFT_SERIAL
      
      
      #define STORE_AES_KEY
      
      
      //#define USER_AES_KEY
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY)
      #error You have to define USER_KEY for boards that does not have UART
      #endif
      
      #ifdef USER_KEY
      /** @brief The user-defined HMAC key to use for personalization */
      #define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store in key slot 0 */
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_KEY
      /** @brief The user-defined soft HMAC key to use for EEPROM personalization */
      #define MY_SOFT_HMAC_KEY 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x010,0x11,0x12,0x13,0x14,0x15,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xAA,0xAB,0xBA,0xBB,0xAC,0xAD,0xAE,0xEB,0xEC,0xED,0xDD
      /** @brief The data to store as soft HMAC key in EEPROM */
      const uint8_t user_soft_key_data[32] = {MY_SOFT_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_SERIAL
      /** @brief The user-defined soft serial to use for EEPROM personalization */
      #define MY_SOFT_SERIAL 0x10,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02
      /** @brief The data to store as soft serial in EEPROM */
      const uint8_t user_soft_serial[9] = {MY_SOFT_SERIAL};
      #endif
      
      #ifdef USER_AES_KEY
      /** @brief The user-defined AES key to use for EEPROM personalization */
      #define MY_AES_KEY 0x15,0x14,0x13,0x12,0x11,0x10,0x09,0x08,0x07,0x06,0x05,0x05,0x04,0x03,0x14,0x15
      /** @brief The data to store as AES key in EEPROM */
      const uint8_t user_aes_key[16] = {MY_AES_KEY};
      #endif
      
      #ifndef USE_SOFT_SIGNING
      const int sha204Pin = MY_SIGNING_ATSHA204_PIN; //!< The IO pin to use for ATSHA204A
      atsha204Class sha204(sha204Pin);
      #endif
      
      /** @brief Print a error notice and halt the execution */
      void halt()
      {
      	Serial.println(F("Halting!"));
      	while(1);
      }
      
      #ifndef USE_SOFT_SIGNING
      
      uint16_t write_config_and_get_crc()
      {
      	uint16_t crc = 0;
      	uint8_t config_word[4];
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	bool do_write;
      
      	
      	for (int i=0; i < 88; i += 4) {
      		do_write = true;
      		if (i == 20) {
      			config_word[0] = 0x8F;
      			config_word[1] = 0x80;
      			config_word[2] = 0x80;
      			config_word[3] = 0xA1;
      		} else if (i == 24) {
      			config_word[0] = 0x82;
      			config_word[1] = 0xE0;
      			config_word[2] = 0xA3;
      			config_word[3] = 0x60;
      		} else if (i == 28) {
      			config_word[0] = 0x94;
      			config_word[1] = 0x40;
      			config_word[2] = 0xA0;
      			config_word[3] = 0x85;
      		} else if (i == 32) {
      			config_word[0] = 0x86;
      			config_word[1] = 0x40;
      			config_word[2] = 0x87;
      			config_word[3] = 0x07;
      		} else if (i == 36) {
      			config_word[0] = 0x0F;
      			config_word[1] = 0x00;
      			config_word[2] = 0x89;
      			config_word[3] = 0xF2;
      		} else if (i == 40) {
      			config_word[0] = 0x8A;
      			config_word[1] = 0x7A;
      			config_word[2] = 0x0B;
      			config_word[3] = 0x8B;
      		} else if (i == 44) {
      			config_word[0] = 0x0C;
      			config_word[1] = 0x4C;
      			config_word[2] = 0xDD;
      			config_word[3] = 0x4D;
      		} else if (i == 48) {
      			config_word[0] = 0xC2;
      			config_word[1] = 0x42;
      			config_word[2] = 0xAF;
      			config_word[3] = 0x8F;
      		} else if (i == 52 || i == 56 || i == 60 || i == 64) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0x00;
      			config_word[2] = 0xFF;
      			config_word[3] = 0x00;
      		} else if (i == 68 || i == 72 || i == 76 || i == 80) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0xFF;
      			config_word[2] = 0xFF;
      			config_word[3] = 0xFF;
      		} else {
      			// All other configs are untouched
      			ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to read config. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      			// Set config_word to the read data
      			config_word[0] = rx_buffer[SHA204_BUFFER_POS_DATA+0];
      			config_word[1] = rx_buffer[SHA204_BUFFER_POS_DATA+1];
      			config_word[2] = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      			config_word[3] = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      			do_write = false;
      		}
      
      		// Update crc with CRC for the current word
      		crc = sha204.calculateAndUpdateCrc(4, config_word, crc);
      
      		// Write config word
      		if (do_write) {
      			ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_CONFIG,
      			                                  i >> 2, 4, config_word, 0, NULL, 0, NULL,
      			                                  WRITE_COUNT_SHORT, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to write config word at address "));
      				Serial.print(i);
      				Serial.print(F(". Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      		}
      	}
      	return crc;
      }
      
      
      void write_key(uint8_t* key)
      {
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      
      	// Write key to slot 0
      	ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_DATA | SHA204_ZONE_COUNT_FLAG,
      	                                  0, SHA204_ZONE_ACCESS_32, key, 0, NULL, 0, NULL,
      	                                  WRITE_COUNT_LONG, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to write key to slot 0. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      }
      #endif // not USE_SOFT_SIGNING
      
      /** @brief Dump current configuration to UART */
      void dump_configuration()
      {
      	uint8_t buffer[32];
      #ifndef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM DATA:"));
      #endif
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      	Serial.print(F("SOFT_HMAC_KEY | "));
      	for (int j=0; j<32; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      	Serial.print(F("SOFT_SERIAL   | "));
      	for (int j=0; j<9; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      	Serial.print(F("AES_KEY       | "));
      	for (int j=0; j<16; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	Serial.println(F("ATSHA204A DATA:"));
      	for (int i=0; i < 88; i += 4) {
      		ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      		if (ret_code != SHA204_SUCCESS) {
      			Serial.print(F("Failed to read config. Response: "));
      			Serial.println(ret_code, HEX);
      			halt();
      		}
      		if (i == 0x00) {
      			Serial.print(F("           SN[0:1]           |         SN[2:3]           | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x04) {
      			Serial.print(F("                          Revnum                         | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x08) {
      			Serial.print(F("                          SN[4:7]                        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x0C) {
      			Serial.print(F("    SN[8]    |  Reserved13   | I2CEnable | Reserved15    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x10) {
      			Serial.print(F("  I2CAddress |  TempOffset   |  OTPmode  | SelectorMode  | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x14) {
      			Serial.print(F("         SlotConfig00        |       SlotConfig01        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x18) {
      			Serial.print(F("         SlotConfig02        |       SlotConfig03        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x1C) {
      			Serial.print(F("         SlotConfig04        |       SlotConfig05        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x20) {
      			Serial.print(F("         SlotConfig06        |       SlotConfig07        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x24) {
      			Serial.print(F("         SlotConfig08        |       SlotConfig09        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x28) {
      			Serial.print(F("         SlotConfig0A        |       SlotConfig0B        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x2C) {
      			Serial.print(F("         SlotConfig0C        |       SlotConfig0D        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x30) {
      			Serial.print(F("         SlotConfig0E        |       SlotConfig0F        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x34) {
      			Serial.print(F("  UseFlag00  | UpdateCount00 | UseFlag01 | UpdateCount01 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x38) {
      			Serial.print(F("  UseFlag02  | UpdateCount02 | UseFlag03 | UpdateCount03 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x3C) {
      			Serial.print(F("  UseFlag04  | UpdateCount04 | UseFlag05 | UpdateCount05 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x40) {
      			Serial.print(F("  UseFlag06  | UpdateCount06 | UseFlag07 | UpdateCount07 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x44) {
      			Serial.print(F("                      LastKeyUse[0:3]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x48) {
      			Serial.print(F("                      LastKeyUse[4:7]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x4C) {
      			Serial.print(F("                      LastKeyUse[8:B]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x50) {
      			Serial.print(F("                      LastKeyUse[C:F]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x54) {
      			Serial.print(F("  UserExtra  |    Selector   | LockValue |  LockConfig   | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		}
      	}
      #endif // not USE_SOFT_SIGNING
      }
      
      /** @brief Sketch setup code */
      void setup()
      {
      	// Delay startup a bit for serial consoles to catch up
      	unsigned long enter = hwMillis();
      	while (hwMillis() - enter < (unsigned long)500);
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	uint8_t lockConfig = 0;
      	uint8_t lockValue = 0;
      	uint16_t crc;
      	(void)crc;
      #else
      	// initialize pseudo-RNG
      	randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
      #endif
      	uint8_t key[32];
      	(void)key;
      
      	Serial.begin(9600);
      	hwInit();
      	Serial.println(F("Personalization sketch for MySensors usage."));
      	Serial.println(F("-------------------------------------------"));
      
      #ifndef USE_SOFT_SIGNING
      	// Wake device before starting operations
      	ret_code = sha204.sha204c_wakeup(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to wake device. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      	// Read out lock config bits to determine if locking is possible
      	ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device lock status. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      		lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      	}
      #endif
      
      #ifdef STORE_SOFT_KEY
      #ifdef USER_SOFT_KEY
      	memcpy(key, user_soft_key_data, 32);
      	Serial.println(F("Using this user supplied soft HMAC key:"));
      #else
      	// Retrieve random value to use as soft HMAC key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 32; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_KEY
      	Serial.print("#define MY_SOFT_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      #endif // STORE_SOFT_KEY
      
      #ifdef STORE_SOFT_SERIAL
      #ifdef USER_SOFT_SERIAL
      	memcpy(key, user_soft_serial, 9);
      	Serial.println(F("Using this user supplied soft serial:"));
      #else
      	// Retrieve random value to use as serial
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 9; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random serial generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 9);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      	} else {
      		Serial.println(F("Serial is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_SERIAL
      	Serial.print("#define MY_SOFT_SERIAL ");
      	for (int i=0; i<9; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 8) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      #endif // STORE_SOFT_SERIAL
      
      #ifdef STORE_AES_KEY
      #ifdef USER_AES_KEY
      	memcpy(key, user_aes_key, 16);
      	Serial.println(F("Using this user supplied AES key:"));
      #else
      	// Retrieve random value to use as key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 16; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This key will be stored in EEPROM as AES key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This key will be stored in EEPROM as AES key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_AES_KEY
      	Serial.print("#define MY_AES_KEY ");
      	for (int i=0; i<16; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 15) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      #endif // STORE_AES_KEY
      
      #ifdef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM configuration:"));
      	dump_configuration();
      #else
      	// Output device revision on console
      	ret_code = sha204.sha204m_dev_rev(tx_buffer, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device revision. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device revision: "));
      		for (int i=0; i<4; i++) {
      			if (rx_buffer[SHA204_BUFFER_POS_DATA+i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+i], HEX);
      		}
      		Serial.println();
      	}
      
      	// Output serial number on console
      	ret_code = sha204.getSerialNumber(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to obtain device serial number. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device serial:   "));
      		Serial.print('{');
      		for (int i=0; i<9; i++) {
      			Serial.print(F("0x"));
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      			if (i < 8) {
      				Serial.print(',');
      			}
      		}
      		Serial.print('}');
      		Serial.println();
      		for (int i=0; i<9; i++) {
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      		}
      		Serial.println();
      	}
      
      	if (lockConfig != 0x00) {
      		// Write config and get CRC for the updated config
      		crc = write_config_and_get_crc();
      
      		// List current configuration before attempting to lock
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      
      #ifdef LOCK_CONFIGURATION
      		// Purge serial input buffer
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character now to lock the configuration..."));
      
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			Serial.println(F("Locking configuration..."));
      
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// Lock configuration zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_CONFIG,
      			                                  crc, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Configuration lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Configuration locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_CONFIGURATION
      		Serial.println(F("Configuration not locked. Define LOCK_CONFIGURATION to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping configuration write and lock (configuration already locked)."));
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      	}
      
      #ifdef SKIP_KEY_STORAGE
      	Serial.println(F("Disable SKIP_KEY_STORAGE to store key."));
      #else
      #ifdef USER_KEY
      	memcpy(key, user_key_data, 32);
      	Serial.println(F("Using this user supplied HMAC key:"));
      #else
      	// Retrieve random value to use as key
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("Take note of this key, it will never be the shown again:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif
      	Serial.print("#define MY_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      		if (i+1 == 16) {
      			Serial.print("\\\n                    ");
      		}
      	}
      	Serial.println();
      
      	// It will not be possible to write the key if the configuration zone is unlocked
      	if (lockConfig == 0x00) {
      		// Write the key to the appropriate slot in the data zone
      		Serial.println(F("Writing key to slot 0..."));
      		write_key(key);
      	} else {
      		Serial.println(F("Skipping key storage (configuration not locked)."));
      		Serial.println(F("The configuration must be locked to be able to write a key."));
      	}
      #endif
      
      	if (lockValue != 0x00) {
      #ifdef LOCK_DATA
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character to lock data..."));
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// If configuration is unlocked, key is not updated. Locking data in this case will cause
      			// slot 0 to contain an unknown (or factory default) key, and this is in practically any
      			// usecase not the desired behaviour, so ask for additional confirmation in this case.
      			if (lockConfig != 0x00) {
      				while (Serial.available()) {
      					Serial.read();
      				}
      				Serial.println(F("*** ATTENTION ***"));
      				Serial.println(F("Configuration is not locked. Are you ABSULOUTELY SURE you want to lock data?"));
      				Serial.println(F("Locking data at this stage will cause slot 0 to contain a factory default key"));
      				Serial.println(
      				    F("which cannot be change after locking is done. This is in practically any usecase"));
      				Serial.println(F("NOT the desired behavour. Send SPACE character now to lock data anyway..."));
      				while (Serial.available() == 0);
      				if (Serial.read() != ' ') {
      					Serial.println(F("Unexpected answer. Skipping lock."));
      					halt();
      				}
      			}
      
      			// Lock data zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_DATA | LOCK_ZONE_NO_CRC,
      			                                  0x0000, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Data lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Data locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_DATA
      		Serial.println(F("Data not locked. Define LOCK_DATA to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping OTP/data zone lock (zone already locked)."));
      	}
      #endif // not USE_SOFT_SIGNING
      
      	Serial.println(F("--------------------------------"));
      	Serial.println(F("Personalization is now complete."));
      #ifndef USE_SOFT_SIGNING
      	Serial.print(F("Configuration is "));
      	if (lockConfig == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      	Serial.print(F("Data is "));
      	if (lockValue == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      #endif
      }
      
      /** @brief Sketch execution code */
      void loop()
      {
      }
      
      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @tbowmo
      sorry can you say me please what i have to add to the sketch that will store my aes key on the sensebender gateway?
      I am a very very noob
      thanks

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      the troubles i have on sensebender gateway its a samd. On the micro (avr based) works fine.
      On the gateway i didnt upload a sketch between. I have uploaded the personalizer sketch and after them i tried the unmoded personalizer.

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      the interesting thing is when i upload the same sketch to the sensebender micro it works the AES Key will be stored correctly.
      But on the Sensebender Gateway only the first two digits

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      i checked the sketch already few times but i dont see an error.
      here is the code i have only change my key with XX

      
      
      #include "sha204_library.h"
      #include "sha204_lib_return_codes.h"
      #define MY_CORE_ONLY
      #include <MySensors.h>
      
      #if DOXYGEN
      #define LOCK_CONFIGURATION
      #define LOCK_DATA
      #define SKIP_KEY_STORAGE
      #define USER_KEY
      #define SKIP_UART_CONFIRMATION
      #define USE_SOFT_SIGNING
      #define STORE_SOFT_KEY
      #define USER_SOFT_KEY
      #define STORE_SOFT_SERIAL
      #define USER_SOFT_SERIAL
      #define STORE_AES_KEY
      #define USER_AES_KEY
      #endif
      
      #define LOCK_CONFIGURATION
      
      //#define LOCK_DATA
      
      //#define SKIP_KEY_STORAGE
      
      #define USER_KEY
      
      //#define SKIP_UART_CONFIRMATION
      
      //#define USE_SOFT_SIGNING
      
      //#define STORE_SOFT_KEY
      
      //#define USER_SOFT_KEY
      
      //#define STORE_SOFT_SERIAL
      
      //#define USER_SOFT_SERIAL
      
      #define STORE_AES_KEY
      
      #define USER_AES_KEY
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY)
      #error You have to define USER_KEY for boards that does not have UART
      #endif
      
      #ifdef USER_KEY
      /** @brief The user-defined HMAC key to use for personalization */
      #define MY_HMAC_KEY 0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX
      /** @brief The data to store in key slot 0 */
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_KEY
      /** @brief The user-defined soft HMAC key to use for EEPROM personalization */
      #define MY_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft HMAC key in EEPROM */
      const uint8_t user_soft_key_data[32] = {MY_SOFT_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_SERIAL
      /** @brief The user-defined soft serial to use for EEPROM personalization */
      #define MY_SOFT_SERIAL 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft serial in EEPROM */
      const uint8_t user_soft_serial[9] = {MY_SOFT_SERIAL};
      #endif
      
      #ifdef USER_AES_KEY
      /** @brief The user-defined AES key to use for EEPROM personalization */
      #define MY_AES_KEY 0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX
      /** @brief The data to store as AES key in EEPROM */
      const uint8_t user_aes_key[16] = {MY_AES_KEY};
      #endif
      
      #ifndef USE_SOFT_SIGNING
      const int sha204Pin = MY_SIGNING_ATSHA204_PIN; //!< The IO pin to use for ATSHA204A
      atsha204Class sha204(sha204Pin);
      #endif
      
      /** @brief Print a error notice and halt the execution */
      void halt()
      {
      	Serial.println(F("Halting!"));
      	while(1);
      }
      
      #ifndef USE_SOFT_SIGNING
      
      uint16_t write_config_and_get_crc()
      {
      	uint16_t crc = 0;
      	uint8_t config_word[4];
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	bool do_write;
      
      	for (int i=0; i < 88; i += 4) {
      		do_write = true;
      		if (i == 20) {
      			config_word[0] = 0x8F;
      			config_word[1] = 0x80;
      			config_word[2] = 0x80;
      			config_word[3] = 0xA1;
      		} else if (i == 24) {
      			config_word[0] = 0x82;
      			config_word[1] = 0xE0;
      			config_word[2] = 0xA3;
      			config_word[3] = 0x60;
      		} else if (i == 28) {
      			config_word[0] = 0x94;
      			config_word[1] = 0x40;
      			config_word[2] = 0xA0;
      			config_word[3] = 0x85;
      		} else if (i == 32) {
      			config_word[0] = 0x86;
      			config_word[1] = 0x40;
      			config_word[2] = 0x87;
      			config_word[3] = 0x07;
      		} else if (i == 36) {
      			config_word[0] = 0x0F;
      			config_word[1] = 0x00;
      			config_word[2] = 0x89;
      			config_word[3] = 0xF2;
      		} else if (i == 40) {
      			config_word[0] = 0x8A;
      			config_word[1] = 0x7A;
      			config_word[2] = 0x0B;
      			config_word[3] = 0x8B;
      		} else if (i == 44) {
      			config_word[0] = 0x0C;
      			config_word[1] = 0x4C;
      			config_word[2] = 0xDD;
      			config_word[3] = 0x4D;
      		} else if (i == 48) {
      			config_word[0] = 0xC2;
      			config_word[1] = 0x42;
      			config_word[2] = 0xAF;
      			config_word[3] = 0x8F;
      		} else if (i == 52 || i == 56 || i == 60 || i == 64) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0x00;
      			config_word[2] = 0xFF;
      			config_word[3] = 0x00;
      		} else if (i == 68 || i == 72 || i == 76 || i == 80) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0xFF;
      			config_word[2] = 0xFF;
      			config_word[3] = 0xFF;
      		} else {
      			// All other configs are untouched
      			ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to read config. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      			// Set config_word to the read data
      			config_word[0] = rx_buffer[SHA204_BUFFER_POS_DATA+0];
      			config_word[1] = rx_buffer[SHA204_BUFFER_POS_DATA+1];
      			config_word[2] = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      			config_word[3] = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      			do_write = false;
      		}
      
      		// Update crc with CRC for the current word
      		crc = sha204.calculateAndUpdateCrc(4, config_word, crc);
      
      		// Write config word
      		if (do_write) {
      			ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_CONFIG,
      			                                  i >> 2, 4, config_word, 0, NULL, 0, NULL,
      			                                  WRITE_COUNT_SHORT, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to write config word at address "));
      				Serial.print(i);
      				Serial.print(F(". Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      		}
      	}
      	return crc;
      }
      
      /**
       * @brief Write provided key to slot 0
       * @param key The key data to write
       */
      void write_key(uint8_t* key)
      {
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      
      	// Write key to slot 0
      	ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_DATA | SHA204_ZONE_COUNT_FLAG,
      	                                  0, SHA204_ZONE_ACCESS_32, key, 0, NULL, 0, NULL,
      	                                  WRITE_COUNT_LONG, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to write key to slot 0. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      }
      #endif // not USE_SOFT_SIGNING
      
      /** @brief Dump current configuration to UART */
      void dump_configuration()
      {
      	uint8_t buffer[32];
      #ifndef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM DATA:"));
      #endif
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      	Serial.print(F("SOFT_HMAC_KEY | "));
      	for (int j=0; j<32; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      	Serial.print(F("SOFT_SERIAL   | "));
      	for (int j=0; j<9; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      	Serial.print(F("AES_KEY       | "));
      	for (int j=0; j<16; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	Serial.println(F("ATSHA204A DATA:"));
      	for (int i=0; i < 88; i += 4) {
      		ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      		if (ret_code != SHA204_SUCCESS) {
      			Serial.print(F("Failed to read config. Response: "));
      			Serial.println(ret_code, HEX);
      			halt();
      		}
      		if (i == 0x00) {
      			Serial.print(F("           SN[0:1]           |         SN[2:3]           | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x04) {
      			Serial.print(F("                          Revnum                         | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x08) {
      			Serial.print(F("                          SN[4:7]                        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x0C) {
      			Serial.print(F("    SN[8]    |  Reserved13   | I2CEnable | Reserved15    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x10) {
      			Serial.print(F("  I2CAddress |  TempOffset   |  OTPmode  | SelectorMode  | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x14) {
      			Serial.print(F("         SlotConfig00        |       SlotConfig01        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x18) {
      			Serial.print(F("         SlotConfig02        |       SlotConfig03        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x1C) {
      			Serial.print(F("         SlotConfig04        |       SlotConfig05        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x20) {
      			Serial.print(F("         SlotConfig06        |       SlotConfig07        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x24) {
      			Serial.print(F("         SlotConfig08        |       SlotConfig09        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x28) {
      			Serial.print(F("         SlotConfig0A        |       SlotConfig0B        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x2C) {
      			Serial.print(F("         SlotConfig0C        |       SlotConfig0D        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x30) {
      			Serial.print(F("         SlotConfig0E        |       SlotConfig0F        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x34) {
      			Serial.print(F("  UseFlag00  | UpdateCount00 | UseFlag01 | UpdateCount01 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x38) {
      			Serial.print(F("  UseFlag02  | UpdateCount02 | UseFlag03 | UpdateCount03 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x3C) {
      			Serial.print(F("  UseFlag04  | UpdateCount04 | UseFlag05 | UpdateCount05 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x40) {
      			Serial.print(F("  UseFlag06  | UpdateCount06 | UseFlag07 | UpdateCount07 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x44) {
      			Serial.print(F("                      LastKeyUse[0:3]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x48) {
      			Serial.print(F("                      LastKeyUse[4:7]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x4C) {
      			Serial.print(F("                      LastKeyUse[8:B]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x50) {
      			Serial.print(F("                      LastKeyUse[C:F]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x54) {
      			Serial.print(F("  UserExtra  |    Selector   | LockValue |  LockConfig   | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		}
      	}
      #endif // not USE_SOFT_SIGNING
      }
      
      /** @brief Sketch setup code */
      void setup()
      {
      	// Delay startup a bit for serial consoles to catch up
      	unsigned long enter = hwMillis();
      	while (hwMillis() - enter < (unsigned long)500);
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	uint8_t lockConfig = 0;
      	uint8_t lockValue = 0;
      	uint16_t crc;
      	(void)crc;
      #else
      	// initialize pseudo-RNG
      	randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
      #endif
      	uint8_t key[32];
      	(void)key;
      
        Serial.begin(9600);
      	hwInit();
      	Serial.println(F("Personalization sketch for MySensors usage."));
      	Serial.println(F("-------------------------------------------"));
      
      #ifndef USE_SOFT_SIGNING
      	// Wake device before starting operations
      	ret_code = sha204.sha204c_wakeup(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to wake device. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      	// Read out lock config bits to determine if locking is possible
      	ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device lock status. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      		lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      	}
      #endif
      
      #ifdef STORE_SOFT_KEY
      #ifdef USER_SOFT_KEY
      	memcpy(key, user_soft_key_data, 32);
      	Serial.println(F("Using this user supplied soft HMAC key:"));
      #else
      	// Retrieve random value to use as soft HMAC key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 32; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_KEY
      	Serial.print("#define MY_SOFT_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      #endif // STORE_SOFT_KEY
      
      #ifdef STORE_SOFT_SERIAL
      #ifdef USER_SOFT_SERIAL
      	memcpy(key, user_soft_serial, 9);
      	Serial.println(F("Using this user supplied soft serial:"));
      #else
      	// Retrieve random value to use as serial
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 9; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random serial generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 9);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      	} else {
      		Serial.println(F("Serial is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_SERIAL
      	Serial.print("#define MY_SOFT_SERIAL ");
      	for (int i=0; i<9; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 8) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      #endif // STORE_SOFT_SERIAL
      
      #ifdef STORE_AES_KEY
      #ifdef USER_AES_KEY
      	memcpy(key, user_aes_key, 16);
      	Serial.println(F("Using this user supplied AES key:"));
      #else
      	// Retrieve random value to use as key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 16; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This key will be stored in EEPROM as AES key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This key will be stored in EEPROM as AES key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_AES_KEY
      	Serial.print("#define MY_AES_KEY ");
      	for (int i=0; i<16; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 15) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      #endif // STORE_AES_KEY
      
      #ifdef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM configuration:"));
      	dump_configuration();
      #else
      	// Output device revision on console
      	ret_code = sha204.sha204m_dev_rev(tx_buffer, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device revision. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device revision: "));
      		for (int i=0; i<4; i++) {
      			if (rx_buffer[SHA204_BUFFER_POS_DATA+i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+i], HEX);
      		}
      		Serial.println();
      	}
      
      	// Output serial number on console
      	ret_code = sha204.getSerialNumber(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to obtain device serial number. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device serial:   "));
      		Serial.print('{');
      		for (int i=0; i<9; i++) {
      			Serial.print(F("0x"));
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      			if (i < 8) {
      				Serial.print(',');
      			}
      		}
      		Serial.print('}');
      		Serial.println();
      		for (int i=0; i<9; i++) {
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      		}
      		Serial.println();
      	}
      
      	if (lockConfig != 0x00) {
      		// Write config and get CRC for the updated config
      		crc = write_config_and_get_crc();
      
      		// List current configuration before attempting to lock
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      
      #ifdef LOCK_CONFIGURATION
      		// Purge serial input buffer
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character now to lock the configuration..."));
      
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			Serial.println(F("Locking configuration..."));
      
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// Lock configuration zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_CONFIG,
      			                                  crc, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Configuration lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Configuration locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_CONFIGURATION
      		Serial.println(F("Configuration not locked. Define LOCK_CONFIGURATION to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping configuration write and lock (configuration already locked)."));
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      	}
      
      #ifdef SKIP_KEY_STORAGE
      	Serial.println(F("Disable SKIP_KEY_STORAGE to store key."));
      #else
      #ifdef USER_KEY
      	memcpy(key, user_key_data, 32);
      	Serial.println(F("Using this user supplied HMAC key:"));
      #else
      	// Retrieve random value to use as key
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("Take note of this key, it will never be the shown again:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif
      	Serial.print("#define MY_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      		if (i+1 == 16) {
      			Serial.print("\\\n                    ");
      		}
      	}
      	Serial.println();
      
      	// It will not be possible to write the key if the configuration zone is unlocked
      	if (lockConfig == 0x00) {
      		// Write the key to the appropriate slot in the data zone
      		Serial.println(F("Writing key to slot 0..."));
      		write_key(key);
      	} else {
      		Serial.println(F("Skipping key storage (configuration not locked)."));
      		Serial.println(F("The configuration must be locked to be able to write a key."));
      	}
      #endif
      
      	if (lockValue != 0x00) {
      #ifdef LOCK_DATA
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character to lock data..."));
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// If configuration is unlocked, key is not updated. Locking data in this case will cause
      			// slot 0 to contain an unknown (or factory default) key, and this is in practically any
      			// usecase not the desired behaviour, so ask for additional confirmation in this case.
      			if (lockConfig != 0x00) {
      				while (Serial.available()) {
      					Serial.read();
      				}
      				Serial.println(F("*** ATTENTION ***"));
      				Serial.println(F("Configuration is not locked. Are you ABSULOUTELY SURE you want to lock data?"));
      				Serial.println(F("Locking data at this stage will cause slot 0 to contain a factory default key"));
      				Serial.println(
      				    F("which cannot be change after locking is done. This is in practically any usecase"));
      				Serial.println(F("NOT the desired behavour. Send SPACE character now to lock data anyway..."));
      				while (Serial.available() == 0);
      				if (Serial.read() != ' ') {
      					Serial.println(F("Unexpected answer. Skipping lock."));
      					halt();
      				}
      			}
      
      			// Lock data zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_DATA | LOCK_ZONE_NO_CRC,
      			                                  0x0000, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Data lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Data locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_DATA
      		Serial.println(F("Data not locked. Define LOCK_DATA to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping OTP/data zone lock (zone already locked)."));
      	}
      #endif // not USE_SOFT_SIGNING
      
      	Serial.println(F("--------------------------------"));
      	Serial.println(F("Personalization is now complete."));
      #ifndef USE_SOFT_SIGNING
      	Serial.print(F("Configuration is "));
      	if (lockConfig == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      	Serial.print(F("Data is "));
      	if (lockValue == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      #endif
      }
      
      /** @brief Sketch execution code */
      void loop()
      {
      }```
      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      ok, i think i know what went wrong! But i dont know how to fix it. On the first run when i tried came the prompt to sens space to lock configuration i did it.
      Now when i upload the modified personalization sketch with my keys i get this output on serial monitor:
      of course i removed my keys with xx!

      Device serial:   {0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX,0xXX}
      xxxxxxxxxxxxxxxxxxxxx
      Skipping configuration write and lock (configuration already locked).
      Chip configuration:
      EEPROM DATA:
      SOFT_HMAC_KEY | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      SOFT_SERIAL   | FFFFFFFFFFFFFFFFFF
      AES_KEY       | XXFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      ATSHA204A DATA:
                 SN[0:1]           |         SN[2:3]           | XX   XX | XX   XX   
                                Revnum                         | 00   09   04   00   
                                SN[4:7]                        | XX   XX   XX   XX   
          SN[8]    |  Reserved13   | I2CEnable | Reserved15    | EE | 10 | 00 | 00   
        I2CAddress |  TempOffset   |  OTPmode  | SelectorMode  | C8 | 00 | 55 | 00   
               SlotConfig00        |       SlotConfig01        | 8F   80 | 80   A1   
               SlotConfig02        |       SlotConfig03        | 82   E0 | A3   60   
               SlotConfig04        |       SlotConfig05        | 94   40 | A0   85   
               SlotConfig06        |       SlotConfig07        | 86   40 | 87   07   
               SlotConfig08        |       SlotConfig09        | 0F   00 | 89   F2   
               SlotConfig0A        |       SlotConfig0B        | 8A   7A | 0B   8B   
               SlotConfig0C        |       SlotConfig0D        | 0C   4C | DD   4D   
               SlotConfig0E        |       SlotConfig0F        | C2   42 | AF   8F   
        UseFlag00  | UpdateCount00 | UseFlag01 | UpdateCount01 | FF | 00 | FF | 00   
        UseFlag02  | UpdateCount02 | UseFlag03 | UpdateCount03 | FF | 00 | FF | 00   
        UseFlag04  | UpdateCount04 | UseFlag05 | UpdateCount05 | FF | 00 | FF | 00   
        UseFlag06  | UpdateCount06 | UseFlag07 | UpdateCount07 | FF | 00 | FF | 00   
                            LastKeyUse[0:3]                    | FF   FF   FF   FF   
                            LastKeyUse[4:7]                    | FF   FF   FF   FF   
                            LastKeyUse[8:B]                    | FF   FF   FF   FF   
                            LastKeyUse[C:F]                    | FF   FF   FF   FF   
        UserExtra  |    Selector   | LockValue |  LockConfig   | 00 | 00 | 55 | 00   
      Using this user supplied HMAC key:
      #define MY_HMAC_KEY 0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,\
                          0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx,0xxx
      Writing key to slot 0...
      Data not locked. Define LOCK_DATA to lock for real.
      --------------------------------
      Personalization is now complete.
      Configuration is LOCKED
      Data is UNLOCKED
      

      i thin this is the reason:

      Skipping configuration write and lock (configuration already locked).
      

      and what i find very interestin that the first two signs of AES Key are correct the rest of them are FFFFF

      AES_KEY       | XXFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      

      is it possible to unlock the configuration or did i kill the chip?
      Thank you
      Greets Eddie

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      when i run the personalizer sketch i see in all keys FFFFFF....... What does it mean that no keys are stored?

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      yes, i try to activate one feature and when it works the next. So i decided to activate the encryption and then when it works then i try to activate the signing. But first i would to check the keys like you said and when i now upload the securitypersonalization sketch unmodified i dont get any output on the serial monitor.
      😞

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      yes the encryption was enabled. Should i upload the personalized sketch again with my keys?

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      Hi, i have just uploaded the GatewayW5100 Sketch to the Gateway and the HumidtyTemp Sketch to the Node and it works fine, but without signing and encryption.

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      and on the node this sketch:

      /*
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       */
      #include <stdint.h>
      #include <pins_arduino.h>
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      #define MY_RADIO_NRF24
      //#define MY_SIGNING_SOFT
      #define MY_SIGNING_ATSHA204
      //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
      #define MY_SIGNING_REQUEST_SIGNATURES
      #ifndef MY_SIGNING_SOFT_RANDOMSEED_PIN
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      #endif
      #ifndef MY_SIGNING_ATSHA204_PIN
      #define MY_SIGNING_ATSHA204_PIN 17
      #endif
      #define MY_RF24_ENABLE_ENCRYPTION
      #include <MySensors.h>
      

      But the node does not connect and i get this on the serial monitor:

      0 MCO:BGN:INIT NODE,CP=RNNNAA-,VER=2.1.1
      4 TSM:INIT
      4 TSF:WUR:MS=0
      12 TSM:INIT:TSP OK
      14 TSF:SID:OK,ID=100
      16 TSM:FPAR
      18 Will not sign message for destination 255 as it does not require it
      67 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2076 !TSM:FPAR:NO REPLY
      2078 TSM:FPAR
      2080 Will not sign message for destination 255 as it does not require it
      2127 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      4139 !TSM:FPAR:NO REPLY
      4141 TSM:FPAR
      4143 Will not sign message for destination 255 as it does not require it
      4190 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      6199 !TSM:FPAR:NO REPLY
      6201 TSM:FPAR
      6203 Will not sign message for destination 255 as it does not require it
      6250 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      8259 !TSM:FPAR:FAIL
      8261 TSM:FAIL:CNT=1
      8263 TSM:FAIL:PDT
      18266 TSM:FAIL:RE-INIT
      18268 TSM:INIT
      18276 TSM:INIT:TSP OK
      18278 TSF:SID:OK,ID=100
      18280 TSM:FPAR
      18282 Will not sign message for destination 255 as it does not require it
      18331 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      20340 !TSM:FPAR:NO REPLY
      20342 TSM:FPAR
      20344 Will not sign message for destination 255 as it does not require it
      20393 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      22403 !TSM:FPAR:NO REPLY
      22405 TSM:FPAR
      22407 Will not sign message for destination 255 as it does not require it
      22456 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      24465 !TSM:FPAR:NO REPLY
      24467 TSM:FPAR
      24469 Will not sign message for destination 255 as it does not require it
      24518 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      26527 !TSM:FPAR:FAIL
      26529 TSM:FAIL:CNT=2
      26531 TSM:FAIL:PDT
      36534 TSM:FAIL:RE-INIT
      36536 TSM:INIT
      36544 TSM:INIT:TSP OK
      36546 TSF:SID:OK,ID=100
      36548 TSM:FPAR
      36550 Will not sign message for destination 255 as it does not require it
      36599 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      38610 !TSM:FPAR:NO REPLY
      38612 TSM:FPAR
      38615 Will not sign message for destination 255 as it does not require it
      38664 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      40673 !TSM:FPAR:NO REPLY
      40675 TSM:FPAR
      40677 Will not sign message for destination 255 as it does not require it
      40726 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      42735 !TSM:FPAR:NO REPLY
      42737 TSM:FPAR
      42739 Will not sign message for destination 255 as it does not require it
      42788 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      44800 !TSM:FPAR:FAIL
      44802 TSM:FAIL:CNT=3
      44804 TSM:FAIL:PDT
      54808 TSM:FAIL:RE-INIT
      54810 TSM:INIT
      54818 TSM:INIT:TSP OK
      54820 TSF:SID:OK,ID=100
      54822 TSM:FPAR
      54824 Will not sign message for destination 255 as it does not require it
      54874 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      56883 !TSM:FPAR:NO REPLY
      56885 TSM:FPAR
      56887 Will not sign message for destination 255 as it does not require it
      56936 TSF:MSG:SEND,100-100-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      

      please help me once again
      Thank you

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      i fear to write again, but my fail story goes on 😞
      i have uploaded on the gateway this sketch:

      /**
      * The MySensors Arduino library handles the wireless radio link and protocol
      * between your home built sensors/actuators and HA controller of choice.
      * The sensors forms a self healing radio network with optional repeaters. Each
      * repeater and gateway builds a routing tables in EEPROM which keeps track of the
      * network topology allowing messages to be routed to nodes.
      *
      * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
      * Copyright (C) 2013-2015 Sensnology AB
      * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
      *
      * Documentation: http://www.mysensors.org
      * Support Forum: http://forum.mysensors.org
      *
      * This program is free software; you can redistribute it and/or
      * modify it under the terms of the GNU General Public License
      * version 2 as published by the Free Software Foundation.
      *
      *******************************
      *
      * REVISION HISTORY
      * Version 1.0 - Henrik EKblad
      * Contribution by a-lurker and Anticimex,
      * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
      * Contribution by Tomas Hozza <thozza@gmail.com>
      *
      *
      * DESCRIPTION
      * The EthernetGateway sends data received from sensors to the ethernet link.
      * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
      *
      * This GW code is designed for Sensebender GateWay / (Arduino Zero variant)
      *
      * Wire connections (OPTIONAL):
      * - Inclusion button should be connected to SW2
      *
      * LEDs on board (default assignments):
      * - Orange: USB RX/TX - Blink when receiving / transmitting on USB CDC device
      * - Yellow: RX  - Blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
      * - Green : TX  - Blink fast on radio message transmitted. In inclusion mode will blink slowly
      * - Red   : ERR - Fast blink on error during transmission error or recieve crc error
      * - Blue  : free - (use with LED_BLUE macro)
      *
      */
      
      #include <stdint.h>
      #include <pins_arduino.h>
      #define SKETCH_VERSION "0.2"
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level.
      //#define MY_RF24_PA_LEVEL RF24_PA_HIGH
      
      #define MY_SIGNING_ATSHA204
      //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
      //#define MY_SIGNING_REQUEST_SIGNATURES
      #ifndef MY_SIGNING_SOFT_RANDOMSEED_PIN
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      #endif                              
      #ifndef MY_SIGNING_ATSHA204_PIN
      #define MY_SIGNING_ATSHA204_PIN 17
      #endif        
      #define MY_RF24_ENABLE_ENCRYPTION
          
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 10,0,0,253   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      #define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      //#define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      #include <SD.h>
      //#include <drivers/ATSHA204/ATSHA204.cpp>
      
      Sd2Card card;
      
      #define EEPROM_VERIFICATION_ADDRESS 0x01
      
      static uint8_t num_of_leds = 5;
      static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};
      
      void setup()
      {
        // Setup locally attached sensors
      }
      
      void presentation()
      {
        // Present locally attached sensors
      }
      
      void loop()
      {
        // Send locally attached sensor data here
      }
      
      
      void preHwInit()
      {
      
        pinMode(MY_SWC1, INPUT_PULLUP);
        pinMode(MY_SWC2, INPUT_PULLUP);
        if (digitalRead(MY_SWC1) && digitalRead(MY_SWC2)) {
          return;
        }
      
        uint8_t tests = 0;
      
        for (int i=0; i< num_of_leds; i++) {
          pinMode(leds[i], OUTPUT);
        }
        uint8_t led_state = 0;
        if (digitalRead(MY_SWC1)) {
          while (!Serial) {
            digitalWrite(LED_BLUE, led_state);
            led_state ^= 0x01;
            delay(500);
          } // Wait for USB to be connected, before spewing out data.
        }
        digitalWrite(LED_BLUE, LOW);
        if (Serial) {
          Serial.println("Sensebender GateWay test routine");
          Serial.print("Mysensors core version : ");
          Serial.println(MYSENSORS_LIBRARY_VERSION);
          Serial.print("GateWay sketch version : ");
          Serial.println(SKETCH_VERSION);
          Serial.println("----------------------------------");
          Serial.println();
        }
        if (testSha204()) {
          digitalWrite(LED_GREEN, HIGH);
          tests++;
        }
        if (testSDCard()) {
          digitalWrite(LED_YELLOW, HIGH);
          tests++;
        }
      
        if (testEEProm()) {
          digitalWrite(LED_ORANGE, HIGH);
          tests++;
        }
        if (testAnalog()) {
          digitalWrite(LED_BLUE, HIGH);
          tests++;
        }
        if (tests == 4) {
          while(1) {
            for (int i=0; i<num_of_leds; i++) {
              digitalWrite(leds[i], HIGH);
              delay(200);
              digitalWrite(leds[i], LOW);
            }
          }
        } else {
          while (1) {
            digitalWrite(LED_RED, HIGH);
            delay(200);
            digitalWrite(LED_RED, LOW);
            delay(200);
          }
        }
      
      }
      
      bool testSha204()
      {
        uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
        uint8_t ret_code;
        if (Serial) {
          Serial.print("- > SHA204 ");
        }
        atsha204_init(MY_SIGNING_ATSHA204_PIN);
        ret_code = atsha204_wakeup(rx_buffer);
      
        if (ret_code == SHA204_SUCCESS) {
          ret_code = atsha204_getSerialNumber(rx_buffer);
          if (ret_code != SHA204_SUCCESS) {
            if (Serial) {
              Serial.println(F("Failed to obtain device serial number. Response: "));
            }
            Serial.println(ret_code, HEX);
          } else {
            if (Serial) {
              Serial.print(F("Ok (serial : "));
              for (int i=0; i<9; i++) {
                if (rx_buffer[i] < 0x10) {
                  Serial.print('0'); // Because Serial.print does not 0-pad HEX
                }
                Serial.print(rx_buffer[i], HEX);
              }
              Serial.println(")");
            }
            return true;
          }
        } else {
          if (Serial) {
            Serial.println(F("Failed to wakeup SHA204"));
          }
        }
        return false;
      }
      
      bool testSDCard()
      {
        if (Serial) {
          Serial.print("- > SD CARD ");
        }
        if (!card.init(SPI_HALF_SPEED, MY_SDCARD_CS)) {
          if (Serial) {
            Serial.println("SD CARD did not initialize!");
          }
        } else {
          if (Serial) {
            Serial.print("SD Card initialized correct! - ");
            Serial.print("type detected : ");
            switch(card.type()) {
            case SD_CARD_TYPE_SD1:
              Serial.println("SD1");
              break;
            case SD_CARD_TYPE_SD2:
              Serial.println("SD2");
              break;
            case SD_CARD_TYPE_SDHC:
              Serial.println("SDHC");
              break;
            default:
              Serial.println("Unknown");
            }
          }
          return true;
        }
        return false;
      }
      
      bool testEEProm()
      {
        uint8_t eeprom_d1, eeprom_d2;
        SerialUSB.print(" -> EEPROM ");
        Wire.begin();
        eeprom_d1 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
        delay(500);
        eeprom_d1 = ~eeprom_d1; // invert the bits
        i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
        delay(500);
        eeprom_d2 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
        if (eeprom_d1 == eeprom_d2) {
          SerialUSB.println("PASSED");
          i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1);
          return true;
        }
        SerialUSB.println("FAILED!");
        return false;
      }
      
      bool testAnalog()
      {
        int bat_detect = analogRead(MY_BAT_DETECT);
        Serial.print("-> analog : ");
        Serial.print(bat_detect);
        if (bat_detect < 400 || bat_detect > 650) {
          Serial.println(" Failed");
          return false;
        }
        Serial.println(" Passed");
        return true;
      }
      
      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      but as i runned the sketch with SKIP_KEY_STORAGE defined, so no keys were generated.

      i did not like to say that the documentation is incorrect, i like your documentation and your work very well! i just didnt understand it!

      Thank you very much!
      Greets Eddie

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex said in 💬 Sensebender Gateway:

      @meddie Sorry, missed that post.
      You have SKIP_KEY_STORAGE defined so no keys will be stored. This is the default and intentional, to avoid people just executing the sketch and accidentally overwrite existing keys.
      Furthermore, you have selected to personalize a ATSHA device, and have it generate the keys. That means that you have to define LOCK_CONFIGURATION or the ATSHA random number generator will not work.

      @Anticimex
      sorry i have one more question, because i didnt fully understand this. In the gettings started how to you wrote:

      Pick a “master” device with serial debug port.
      Set the following sketch configuration of the personalizer:
      ...
      
      Enable SKIP_KEY_STORAGE
      ...
      
      Execute the sketch on the “master” device to obtain a randomized key. Save this key to a secure location and keep it confidential so that you can retrieve it if you need to personalize more devices later on.
      Now reconfigure the sketch with these settings:
      ...
      Disable SKIP_KEY_STORAGE
      ...
      Put the saved key in the user_key_data variable.
      Now execute the sketch on all devices you want to personalize with this secret key.
      

      on the first run i have to enable SKIP_KEY_STORAGE so i removed the comments.
      But here in forum you write i have to disable this. After i has disabled it wroked fine for me.

      But now i have to run the sketch on my node, and i think i have to disable the SKIP function too, because i need that the keys will be stored in the node.

      So if i am right, the on both runs the SKIP function has to be commented out? Or i am wrong?
      Thank you.

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      sorry sorry for so many questions, i have read the how to use already some times, but maybe its my bad english or the fear to do something wrong or to destroy the chip. I get a little bit unsure.

      Now i get both keys. If i understood correctly, the keys are now stored, i have now to put the shown keys to the sketch as HMAC and AES Key, and run this sketch on the sensor nodes.
      On the gateway on which i generated the keys i dont need to do anything more as to upload the gateway sketch ?
      Thank you very much for your support!

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      Ah, thank you very much, yes now i get generated a key. But one more question the AES key will not be generated? I got only the HMAC Key, do i have to put the AES Key at myself?
      Thank you very much!

      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      @Anticimex
      Hi i have posted my sketch few posts ago, but no problem here is it:

      
      
      #include "sha204_library.h"
      #include "sha204_lib_return_codes.h"
      #define MY_CORE_ONLY
      #include <MySensors.h>
      
      #if DOXYGEN
      #define LOCK_CONFIGURATION
      #define LOCK_DATA
      #define SKIP_KEY_STORAGE
      #define USER_KEY
      #define SKIP_UART_CONFIRMATION
      #define USE_SOFT_SIGNING
      #define STORE_SOFT_KEY
      #define USER_SOFT_KEY
      #define STORE_SOFT_SERIAL
      #define USER_SOFT_SERIAL
      #define STORE_AES_KEY
      #define USER_AES_KEY
      #endif
      
      //#define LOCK_CONFIGURATION
      
      //#define LOCK_DATA
      
      #define SKIP_KEY_STORAGE
      
      //#define USER_KEY
      
      //#define SKIP_UART_CONFIRMATION
      
      //#define USE_SOFT_SIGNING
      
      //#define STORE_SOFT_KEY
      
      //#define USER_SOFT_KEY
      
      //#define STORE_SOFT_SERIAL
      
      //#define USER_SOFT_SERIAL
      
      //#define STORE_AES_KEY
      
      //#define USER_AES_KEY
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY)
      #error You have to define USER_KEY for boards that does not have UART
      #endif
      
      #ifdef USER_KEY
      /** @brief The user-defined HMAC key to use for personalization */
      #define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store in key slot 0 */
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_KEY
      /** @brief The user-defined soft HMAC key to use for EEPROM personalization */
      #define MY_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft HMAC key in EEPROM */
      const uint8_t user_soft_key_data[32] = {MY_SOFT_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_SERIAL
      /** @brief The user-defined soft serial to use for EEPROM personalization */
      #define MY_SOFT_SERIAL 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft serial in EEPROM */
      const uint8_t user_soft_serial[9] = {MY_SOFT_SERIAL};
      #endif
      
      #ifdef USER_AES_KEY
      /** @brief The user-defined AES key to use for EEPROM personalization */
      #define MY_AES_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as AES key in EEPROM */
      const uint8_t user_aes_key[16] = {MY_AES_KEY};
      #endif
      
      #ifndef USE_SOFT_SIGNING
      const int sha204Pin = MY_SIGNING_ATSHA204_PIN; //!< The IO pin to use for ATSHA204A
      atsha204Class sha204(sha204Pin);
      #endif
      
      /** @brief Print a error notice and halt the execution */
      void halt()
      {
      	Serial.println(F("Halting!"));
      	while(1);
      }
      
      #ifndef USE_SOFT_SIGNING
      
      uint16_t write_config_and_get_crc()
      {
      	uint16_t crc = 0;
      	uint8_t config_word[4];
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	bool do_write;
      
      	for (int i=0; i < 88; i += 4) {
      		do_write = true;
      		if (i == 20) {
      			config_word[0] = 0x8F;
      			config_word[1] = 0x80;
      			config_word[2] = 0x80;
      			config_word[3] = 0xA1;
      		} else if (i == 24) {
      			config_word[0] = 0x82;
      			config_word[1] = 0xE0;
      			config_word[2] = 0xA3;
      			config_word[3] = 0x60;
      		} else if (i == 28) {
      			config_word[0] = 0x94;
      			config_word[1] = 0x40;
      			config_word[2] = 0xA0;
      			config_word[3] = 0x85;
      		} else if (i == 32) {
      			config_word[0] = 0x86;
      			config_word[1] = 0x40;
      			config_word[2] = 0x87;
      			config_word[3] = 0x07;
      		} else if (i == 36) {
      			config_word[0] = 0x0F;
      			config_word[1] = 0x00;
      			config_word[2] = 0x89;
      			config_word[3] = 0xF2;
      		} else if (i == 40) {
      			config_word[0] = 0x8A;
      			config_word[1] = 0x7A;
      			config_word[2] = 0x0B;
      			config_word[3] = 0x8B;
      		} else if (i == 44) {
      			config_word[0] = 0x0C;
      			config_word[1] = 0x4C;
      			config_word[2] = 0xDD;
      			config_word[3] = 0x4D;
      		} else if (i == 48) {
      			config_word[0] = 0xC2;
      			config_word[1] = 0x42;
      			config_word[2] = 0xAF;
      			config_word[3] = 0x8F;
      		} else if (i == 52 || i == 56 || i == 60 || i == 64) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0x00;
      			config_word[2] = 0xFF;
      			config_word[3] = 0x00;
      		} else if (i == 68 || i == 72 || i == 76 || i == 80) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0xFF;
      			config_word[2] = 0xFF;
      			config_word[3] = 0xFF;
      		} else {
      			// All other configs are untouched
      			ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to read config. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      			// Set config_word to the read data
      			config_word[0] = rx_buffer[SHA204_BUFFER_POS_DATA+0];
      			config_word[1] = rx_buffer[SHA204_BUFFER_POS_DATA+1];
      			config_word[2] = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      			config_word[3] = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      			do_write = false;
      		}
      
      		// Update crc with CRC for the current word
      		crc = sha204.calculateAndUpdateCrc(4, config_word, crc);
      
      		// Write config word
      		if (do_write) {
      			ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_CONFIG,
      			                                  i >> 2, 4, config_word, 0, NULL, 0, NULL,
      			                                  WRITE_COUNT_SHORT, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to write config word at address "));
      				Serial.print(i);
      				Serial.print(F(". Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      		}
      	}
      	return crc;
      }
      
      /**
       * @brief Write provided key to slot 0
       * @param key The key data to write
       */
      void write_key(uint8_t* key)
      {
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      
      	// Write key to slot 0
      	ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_DATA | SHA204_ZONE_COUNT_FLAG,
      	                                  0, SHA204_ZONE_ACCESS_32, key, 0, NULL, 0, NULL,
      	                                  WRITE_COUNT_LONG, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to write key to slot 0. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      }
      #endif // not USE_SOFT_SIGNING
      
      /** @brief Dump current configuration to UART */
      void dump_configuration()
      {
      	uint8_t buffer[32];
      #ifndef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM DATA:"));
      #endif
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      	Serial.print(F("SOFT_HMAC_KEY | "));
      	for (int j=0; j<32; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      	Serial.print(F("SOFT_SERIAL   | "));
      	for (int j=0; j<9; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      	Serial.print(F("AES_KEY       | "));
      	for (int j=0; j<16; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	Serial.println(F("ATSHA204A DATA:"));
      	for (int i=0; i < 88; i += 4) {
      		ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      		if (ret_code != SHA204_SUCCESS) {
      			Serial.print(F("Failed to read config. Response: "));
      			Serial.println(ret_code, HEX);
      			halt();
      		}
      		if (i == 0x00) {
      			Serial.print(F("           SN[0:1]           |         SN[2:3]           | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x04) {
      			Serial.print(F("                          Revnum                         | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x08) {
      			Serial.print(F("                          SN[4:7]                        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x0C) {
      			Serial.print(F("    SN[8]    |  Reserved13   | I2CEnable | Reserved15    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x10) {
      			Serial.print(F("  I2CAddress |  TempOffset   |  OTPmode  | SelectorMode  | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x14) {
      			Serial.print(F("         SlotConfig00        |       SlotConfig01        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x18) {
      			Serial.print(F("         SlotConfig02        |       SlotConfig03        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x1C) {
      			Serial.print(F("         SlotConfig04        |       SlotConfig05        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x20) {
      			Serial.print(F("         SlotConfig06        |       SlotConfig07        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x24) {
      			Serial.print(F("         SlotConfig08        |       SlotConfig09        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x28) {
      			Serial.print(F("         SlotConfig0A        |       SlotConfig0B        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x2C) {
      			Serial.print(F("         SlotConfig0C        |       SlotConfig0D        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x30) {
      			Serial.print(F("         SlotConfig0E        |       SlotConfig0F        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x34) {
      			Serial.print(F("  UseFlag00  | UpdateCount00 | UseFlag01 | UpdateCount01 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x38) {
      			Serial.print(F("  UseFlag02  | UpdateCount02 | UseFlag03 | UpdateCount03 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x3C) {
      			Serial.print(F("  UseFlag04  | UpdateCount04 | UseFlag05 | UpdateCount05 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x40) {
      			Serial.print(F("  UseFlag06  | UpdateCount06 | UseFlag07 | UpdateCount07 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x44) {
      			Serial.print(F("                      LastKeyUse[0:3]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x48) {
      			Serial.print(F("                      LastKeyUse[4:7]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x4C) {
      			Serial.print(F("                      LastKeyUse[8:B]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x50) {
      			Serial.print(F("                      LastKeyUse[C:F]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x54) {
      			Serial.print(F("  UserExtra  |    Selector   | LockValue |  LockConfig   | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		}
      	}
      #endif // not USE_SOFT_SIGNING
      }
      
      /** @brief Sketch setup code */
      void setup()
      {
      	// Delay startup a bit for serial consoles to catch up
      	unsigned long enter = hwMillis();
      	while (hwMillis() - enter < (unsigned long)500);
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	uint8_t lockConfig = 0;
      	uint8_t lockValue = 0;
      	uint16_t crc;
      	(void)crc;
      #else
      	// initialize pseudo-RNG
      	randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
      #endif
      	uint8_t key[32];
      	(void)key;
      
      	Serial.begin(115200);
      	hwInit();
      	Serial.println(F("Personalization sketch for MySensors usage."));
      	Serial.println(F("-------------------------------------------"));
      
      #ifndef USE_SOFT_SIGNING
      	// Wake device before starting operations
      	ret_code = sha204.sha204c_wakeup(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to wake device. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      	// Read out lock config bits to determine if locking is possible
      	ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device lock status. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      		lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      	}
      #endif
      
      #ifdef STORE_SOFT_KEY
      #ifdef USER_SOFT_KEY
      	memcpy(key, user_soft_key_data, 32);
      	Serial.println(F("Using this user supplied soft HMAC key:"));
      #else
      	// Retrieve random value to use as soft HMAC key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 32; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_KEY
      	Serial.print("#define MY_SOFT_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      #endif // STORE_SOFT_KEY
      
      #ifdef STORE_SOFT_SERIAL
      #ifdef USER_SOFT_SERIAL
      	memcpy(key, user_soft_serial, 9);
      	Serial.println(F("Using this user supplied soft serial:"));
      #else
      	// Retrieve random value to use as serial
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 9; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random serial generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 9);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      	} else {
      		Serial.println(F("Serial is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_SERIAL
      	Serial.print("#define MY_SOFT_SERIAL ");
      	for (int i=0; i<9; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 8) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      #endif // STORE_SOFT_SERIAL
      
      #ifdef STORE_AES_KEY
      #ifdef USER_AES_KEY
      	memcpy(key, user_aes_key, 16);
      	Serial.println(F("Using this user supplied AES key:"));
      #else
      	// Retrieve random value to use as key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 16; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This key will be stored in EEPROM as AES key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This key will be stored in EEPROM as AES key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_AES_KEY
      	Serial.print("#define MY_AES_KEY ");
      	for (int i=0; i<16; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 15) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      #endif // STORE_AES_KEY
      
      #ifdef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM configuration:"));
      	dump_configuration();
      #else
      	// Output device revision on console
      	ret_code = sha204.sha204m_dev_rev(tx_buffer, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device revision. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device revision: "));
      		for (int i=0; i<4; i++) {
      			if (rx_buffer[SHA204_BUFFER_POS_DATA+i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+i], HEX);
      		}
      		Serial.println();
      	}
      
      	// Output serial number on console
      	ret_code = sha204.getSerialNumber(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to obtain device serial number. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		Serial.print(F("Device serial:   "));
      		Serial.print('{');
      		for (int i=0; i<9; i++) {
      			Serial.print(F("0x"));
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      			if (i < 8) {
      				Serial.print(',');
      			}
      		}
      		Serial.print('}');
      		Serial.println();
      		for (int i=0; i<9; i++) {
      			if (rx_buffer[i] < 0x10) {
      				Serial.print('0'); // Because Serial.print does not 0-pad HEX
      			}
      			Serial.print(rx_buffer[i], HEX);
      		}
      		Serial.println();
      	}
      
      	if (lockConfig != 0x00) {
      		// Write config and get CRC for the updated config
      		crc = write_config_and_get_crc();
      
      		// List current configuration before attempting to lock
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      
      #ifdef LOCK_CONFIGURATION
      		// Purge serial input buffer
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character now to lock the configuration..."));
      
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			Serial.println(F("Locking configuration..."));
      
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// Lock configuration zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_CONFIG,
      			                                  crc, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Configuration lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Configuration locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_CONFIGURATION
      		Serial.println(F("Configuration not locked. Define LOCK_CONFIGURATION to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping configuration write and lock (configuration already locked)."));
      		Serial.println(F("Chip configuration:"));
      		dump_configuration();
      	}
      
      #ifdef SKIP_KEY_STORAGE
      	Serial.println(F("Disable SKIP_KEY_STORAGE to store key."));
      #else
      #ifdef USER_KEY
      	memcpy(key, user_key_data, 32);
      	Serial.println(F("Using this user supplied HMAC key:"));
      #else
      	// Retrieve random value to use as key
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("Take note of this key, it will never be the shown again:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif
      	Serial.print("#define MY_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      		if (i+1 == 16) {
      			Serial.print("\\\n                    ");
      		}
      	}
      	Serial.println();
      
      	// It will not be possible to write the key if the configuration zone is unlocked
      	if (lockConfig == 0x00) {
      		// Write the key to the appropriate slot in the data zone
      		Serial.println(F("Writing key to slot 0..."));
      		write_key(key);
      	} else {
      		Serial.println(F("Skipping key storage (configuration not locked)."));
      		Serial.println(F("The configuration must be locked to be able to write a key."));
      	}
      #endif
      
      	if (lockValue != 0x00) {
      #ifdef LOCK_DATA
      #ifndef SKIP_UART_CONFIRMATION
      		while (Serial.available()) {
      			Serial.read();
      		}
      		Serial.println(F("Send SPACE character to lock data..."));
      		while (Serial.available() == 0);
      		if (Serial.read() == ' ')
      #endif //not SKIP_UART_CONFIRMATION
      		{
      			// Correct sequence, resync chip
      			ret_code = sha204.sha204c_resync(SHA204_RSP_SIZE_MAX, rx_buffer);
      			if (ret_code != SHA204_SUCCESS && ret_code != SHA204_RESYNC_WITH_WAKEUP) {
      				Serial.print(F("Resync failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      
      			// If configuration is unlocked, key is not updated. Locking data in this case will cause
      			// slot 0 to contain an unknown (or factory default) key, and this is in practically any
      			// usecase not the desired behaviour, so ask for additional confirmation in this case.
      			if (lockConfig != 0x00) {
      				while (Serial.available()) {
      					Serial.read();
      				}
      				Serial.println(F("*** ATTENTION ***"));
      				Serial.println(F("Configuration is not locked. Are you ABSULOUTELY SURE you want to lock data?"));
      				Serial.println(F("Locking data at this stage will cause slot 0 to contain a factory default key"));
      				Serial.println(
      				    F("which cannot be change after locking is done. This is in practically any usecase"));
      				Serial.println(F("NOT the desired behavour. Send SPACE character now to lock data anyway..."));
      				while (Serial.available() == 0);
      				if (Serial.read() != ' ') {
      					Serial.println(F("Unexpected answer. Skipping lock."));
      					halt();
      				}
      			}
      
      			// Lock data zone
      			ret_code = sha204.sha204m_execute(SHA204_LOCK, SHA204_ZONE_DATA | LOCK_ZONE_NO_CRC,
      			                                  0x0000, 0, NULL, 0, NULL, 0, NULL,
      			                                  LOCK_COUNT, tx_buffer, LOCK_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Data lock failed. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			} else {
      				Serial.println(F("Data locked."));
      
      				// Update lock flags after locking
      				ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      				if (ret_code != SHA204_SUCCESS) {
      					Serial.print(F("Failed to determine device lock status. Response: "));
      					Serial.println(ret_code, HEX);
      					halt();
      				} else {
      					lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      					lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      				}
      			}
      		}
      #ifndef SKIP_UART_CONFIRMATION
      		else {
      			Serial.println(F("Unexpected answer. Skipping lock."));
      		}
      #endif //not SKIP_UART_CONFIRMATION
      #else //LOCK_DATA
      		Serial.println(F("Data not locked. Define LOCK_DATA to lock for real."));
      #endif
      	} else {
      		Serial.println(F("Skipping OTP/data zone lock (zone already locked)."));
      	}
      #endif // not USE_SOFT_SIGNING
      
      	Serial.println(F("--------------------------------"));
      	Serial.println(F("Personalization is now complete."));
      #ifndef USE_SOFT_SIGNING
      	Serial.print(F("Configuration is "));
      	if (lockConfig == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      	Serial.print(F("Data is "));
      	if (lockValue == 0x00) {
      		Serial.println("LOCKED");
      	} else {
      		Serial.println("UNLOCKED");
      	}
      #endif
      }
      
      /** @brief Sketch execution code */
      void loop()
      {
      }```
      posted in Development
      meddie
    • RE: [security] Introducing signing support to MySensors

      ok, thank you, but do you know why the sketch didnt generate the keys, and instead of random i get only keys ffffffffffff ?
      thank you

      posted in Development
      meddie
    • RE: 💬 Sensebender Gateway

      i just get the output, the serial console must be open while uploading the sketch, immedialty after the upload i see the output.
      But all Keys are FFFFFFF

      SOFT_HMAC_KEY | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      SOFT_SERIAL   | FFFFFFFFFFFFFFFFFF
      AES_KEY       | FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
      ATSHA204A DATA:
      
      

      Why this?

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Gateway

      yes i have seen this an my console is set to 115200 bauds, but no output

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Gateway

      i have uploaded this securitypersonalizer.ino sketch:

      /*
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       */
      /**
       * @ingroup MySigninggrp
       * @{
       * @file SecurityPersonalizer.ino
       * @brief Security personalization sketch
       *
       * REVISION HISTORY
       *  - See git log (git log libraries/MySensors/examples/SecurityPersonalizer/SecurityPersonalizer.ino)
       */
      
      /**
       * @example SecurityPersonalizer.ino
       * This sketch will personalize either none-volatile memory or ATSHA204A for security functions
       * available in the MySensors library.
       *
       * For ATSHA204A:
       * It will write factory default settings to the configuration zone
       * and then lock it.<br>
       * It will then either<br>
       * -# Generate a random value to use as a key which will be stored in
       * slot 0. The key is printed on UART (115200) in clear text for the user to be
       * able to use it as a user-supplied key in other personalization executions
       * where the same key is needed.
       * -# Use a user-supplied value to use as a key which will be stored in
       * slot 0.
       * Finally it will lock the data zone.
       *
       * By default, no locking is performed. User have to manually enable the flags that
       * turn on the locking. Furthermore, user have to send a SPACE character on serial
       * console when prompted to do any locking. On boards that does not provide UART
       * input it is possible to configure the sketch to skip this confirmation.
       * Default settings use ATSHA204A on @ref MY_SIGNING_ATSHA204_PIN.
       *
       * For Soft signing:
       * It will<br>
       * -# Generate a random value to use as a key which will be stored in EEPROM.
       * The key is printed on UART (115200) in clear text for the user to be ablle to
       * use it as a user-supplied key in other personalization executions where the same
       * key is needed.
       * -# Use a user-supplied value to use as a key which will be stored in EEPROM.
       * -# Generate a random value to use as a serial number which will be stored in EEPROM.
       * The serial number is printed on UART (115200) in clear text for the user to be ablle to
       * use it as a user-supplied serial number in other personalization executions where the
       * serial is needed (typically for a whitelist).
       * -# Use a user-supplied value to use as a serial which will be stored in EEPROM.
       *
       * For Encryption support:
       * -# Generate a random value to use as a AES key which will be stored in EEPROM.
       * The AES key is printed on UART (115200) in clear text for the user to be ablle to
       * use it as a user-supplied AES key in other personalization executions where the
       * AES key is needed (typically for RF encryption).
       * -# Use a user-supplied value to use as a AES key which will be stored in EEPROM.
       *
       * Personalizing EEPROM or ATSHA204A still require the appropriate configuration of the
       * library to actually have an effect. There is no problem personalizing EEPROM and
       * ATSHA204A at the same time. There is however a security risk with using the same
       * data for EEPROM and ATSHA204A so it is recommended to use different serial and HMAC
       * keys on the same device for ATSHA204A vs soft signing settings.
       *
       * Details on personalization procedure is given in @ref personalization.
       */
      
      #include "sha204_library.h"
      #include "sha204_lib_return_codes.h"
      #define MY_CORE_ONLY
      #include <MySensors.h>
      
      // Doxygen specific constructs, not included when built normally
      // This is used to enable disabled macros/definitions to be included in the documentation as well.
      #if DOXYGEN
      #define LOCK_CONFIGURATION
      #define LOCK_DATA
      #define SKIP_KEY_STORAGE
      #define USER_KEY
      #define SKIP_UART_CONFIRMATION
      #define USE_SOFT_SIGNING
      #define STORE_SOFT_KEY
      #define USER_SOFT_KEY
      #define STORE_SOFT_SERIAL
      #define USER_SOFT_SERIAL
      #define STORE_AES_KEY
      #define USER_AES_KEY
      #endif
      
      /**
       * @def LOCK_CONFIGURATION
       * @brief Uncomment this to enable locking the configuration zone.
       *
       * It is still possible to change the key, and this also enable random key generation.
       * @warning BE AWARE THAT THIS PREVENTS ANY FUTURE CONFIGURATION CHANGE TO THE CHIP
       */
      #define LOCK_CONFIGURATION
      
      /**
       * @def LOCK_DATA
       * @brief Uncomment this to enable locking the data zone.
       *
       * It is not required to lock data, key cannot be retrieved anyway, but by locking
       * data, it can be guaranteed that nobody even with physical access to the chip,
       * will be able to change the key.
       * @warning BE AWARE THAT THIS PREVENTS THE KEY TO BE CHANGED
       */
      //#define LOCK_DATA
      
      /**
       * @def SKIP_KEY_STORAGE
       * @brief Uncomment this to skip key storage (typically once key has been written once)
       */
      #define SKIP_KEY_STORAGE
      
      /**
       * @def USER_KEY
       * @brief Uncomment this to skip key generation and use @ref user_key_data as key instead.
       */
      //#define USER_KEY
      
      /**
       * @def SKIP_UART_CONFIRMATION
       * @brief Uncomment this for boards that lack UART
       *
       * @b Important<br> No confirmation will be required for locking any zones with this configuration!
       * Also, key generation is not permitted in this mode as there is no way of presenting the generated key.
       */
      //#define SKIP_UART_CONFIRMATION
      
      /**
       * @def USE_SOFT_SIGNING
       * @brief Uncomment this to store data to EEPROM instead of ATSHA204A
       */
      //#define USE_SOFT_SIGNING
      
      /**
       * @def STORE_SOFT_KEY
       * @brief Uncomment this to store soft HMAC key to EEPROM
       */
      //#define STORE_SOFT_KEY
      
      /**
       * @def USER_SOFT_KEY
       * @brief Uncomment this to skip soft HMAC key generation and use @ref user_soft_key_data as HMAC key instead.
       */
      //#define USER_SOFT_KEY
      
      /**
       * @def STORE_SOFT_SERIAL
       * @brief Uncomment this to store soft serial to EEPROM
       */
      //#define STORE_SOFT_SERIAL
      
      /**
       * @def USER_SOFT_SERIAL
       * @brief Uncomment this to skip soft serial generation and use @ref user_soft_serial as serial instead.
       */
      //#define USER_SOFT_SERIAL
      
      /**
       * @def STORE_AES_KEY
       * @brief Uncomment this to store AES key to EEPROM
       */
      //#define STORE_AES_KEY
      
      /**
       * @def USER_AES_KEY
       * @brief Uncomment this to skip AES key generation and use @ref user_aes_key as key instead.
       */
      //#define USER_AES_KEY
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY)
      #error You have to define USER_KEY for boards that does not have UART
      #endif
      
      #ifdef USER_KEY
      /** @brief The user-defined HMAC key to use for personalization */
      #define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store in key slot 0 */
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_KEY
      /** @brief The user-defined soft HMAC key to use for EEPROM personalization */
      #define MY_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft HMAC key in EEPROM */
      const uint8_t user_soft_key_data[32] = {MY_SOFT_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_SERIAL
      /** @brief The user-defined soft serial to use for EEPROM personalization */
      #define MY_SOFT_SERIAL 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft serial in EEPROM */
      const uint8_t user_soft_serial[9] = {MY_SOFT_SERIAL};
      #endif
      
      #ifdef USER_AES_KEY
      /** @brief The user-defined AES key to use for EEPROM personalization */
      #define MY_AES_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as AES key in EEPROM */
      const uint8_t user_aes_key[16] = {MY_AES_KEY};
      #endif
      
      #ifndef USE_SOFT_SIGNING
      const int sha204Pin = MY_SIGNING_ATSHA204_PIN; //!< The IO pin to use for ATSHA204A
      atsha204Class sha204(sha204Pin);
      #endif
      
      /** @brief Print a error notice and halt the execution */
      void halt()
      {
      	Serial.println(F("Halting!"));
      	while(1);
      }
      
      #ifndef USE_SOFT_SIGNING
      /**
       * @brief Write default configuration and return CRC of the configuration bits
       * @returns CRC over the configuration bits
       */
      uint16_t write_config_and_get_crc()
      {
      	uint16_t crc = 0;
      	uint8_t config_word[4];
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	bool do_write;
      
      	// We will set default settings from datasheet on all slots. This means that we can use slot 0 for the key
      	// as that slot will not be readable (key will therefore be secure) and slot 8 for the payload digest
      	// calculationon as that slot can be written in clear text even when the datazone is locked.
      	// Other settings which are not relevant are kept as is.
      
      	for (int i=0; i < 88; i += 4) {
      		do_write = true;
      		if (i == 20) {
      			config_word[0] = 0x8F;
      			config_word[1] = 0x80;
      			config_word[2] = 0x80;
      			config_word[3] = 0xA1;
      		} else if (i == 24) {
      			config_word[0] = 0x82;
      			config_word[1] = 0xE0;
      			config_word[2] = 0xA3;
      			config_word[3] = 0x60;
      		} else if (i == 28) {
      			config_word[0] = 0x94;
      			config_word[1] = 0x40;
      			config_word[2] = 0xA0;
      			config_word[3] = 0x85;
      		} else if (i == 32) {
      			config_word[0] = 0x86;
      			config_word[1] = 0x40;
      			config_word[2] = 0x87;
      			config_word[3] = 0x07;
      		} else if (i == 36) {
      			config_word[0] = 0x0F;
      			config_word[1] = 0x00;
      			config_word[2] = 0x89;
      			config_word[3] = 0xF2;
      		} else if (i == 40) {
      			config_word[0] = 0x8A;
      			config_word[1] = 0x7A;
      			config_word[2] = 0x0B;
      			config_word[3] = 0x8B;
      		} else if (i == 44) {
      			config_word[0] = 0x0C;
      			config_word[1] = 0x4C;
      			config_word[2] = 0xDD;
      			config_word[3] = 0x4D;
      		} else if (i == 48) {
      			config_word[0] = 0xC2;
      			config_word[1] = 0x42;
      			config_word[2] = 0xAF;
      			config_word[3] = 0x8F;
      		} else if (i == 52 || i == 56 || i == 60 || i == 64) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0x00;
      			config_word[2] = 0xFF;
      			config_word[3] = 0x00;
      		} else if (i == 68 || i == 72 || i == 76 || i == 80) {
      			config_word[0] = 0xFF;
      			config_word[1] = 0xFF;
      			config_word[2] = 0xFF;
      			config_word[3] = 0xFF;
      		} else {
      			// All other configs are untouched
      			ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to read config. Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      			// Set config_word to the read data
      			config_word[0] = rx_buffer[SHA204_BUFFER_POS_DATA+0];
      			config_word[1] = rx_buffer[SHA204_BUFFER_POS_DATA+1];
      			config_word[2] = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      			config_word[3] = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      			do_write = false;
      		}
      
      		// Update crc with CRC for the current word
      		crc = sha204.calculateAndUpdateCrc(4, config_word, crc);
      
      		// Write config word
      		if (do_write) {
      			ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_CONFIG,
      			                                  i >> 2, 4, config_word, 0, NULL, 0, NULL,
      			                                  WRITE_COUNT_SHORT, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      			if (ret_code != SHA204_SUCCESS) {
      				Serial.print(F("Failed to write config word at address "));
      				Serial.print(i);
      				Serial.print(F(". Response: "));
      				Serial.println(ret_code, HEX);
      				halt();
      			}
      		}
      	}
      	return crc;
      }
      
      /**
       * @brief Write provided key to slot 0
       * @param key The key data to write
       */
      void write_key(uint8_t* key)
      {
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      
      	// Write key to slot 0
      	ret_code = sha204.sha204m_execute(SHA204_WRITE, SHA204_ZONE_DATA | SHA204_ZONE_COUNT_FLAG,
      	                                  0, SHA204_ZONE_ACCESS_32, key, 0, NULL, 0, NULL,
      	                                  WRITE_COUNT_LONG, tx_buffer, WRITE_RSP_SIZE, rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to write key to slot 0. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      }
      #endif // not USE_SOFT_SIGNING
      
      /** @brief Dump current configuration to UART */
      void dump_configuration()
      {
      	uint8_t buffer[32];
      #ifndef USE_SOFT_SIGNING
      	Serial.println(F("EEPROM DATA:"));
      #endif
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      	Serial.print(F("SOFT_HMAC_KEY | "));
      	for (int j=0; j<32; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      	Serial.print(F("SOFT_SERIAL   | "));
      	for (int j=0; j<9; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      	hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
      	Serial.print(F("AES_KEY       | "));
      	for (int j=0; j<16; j++) {
      		if (buffer[j] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(buffer[j], HEX);
      	}
      	Serial.println();
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	Serial.println(F("ATSHA204A DATA:"));
      	for (int i=0; i < 88; i += 4) {
      		ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, i);
      		if (ret_code != SHA204_SUCCESS) {
      			Serial.print(F("Failed to read config. Response: "));
      			Serial.println(ret_code, HEX);
      			halt();
      		}
      		if (i == 0x00) {
      			Serial.print(F("           SN[0:1]           |         SN[2:3]           | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x04) {
      			Serial.print(F("                          Revnum                         | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x08) {
      			Serial.print(F("                          SN[4:7]                        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x0C) {
      			Serial.print(F("    SN[8]    |  Reserved13   | I2CEnable | Reserved15    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x10) {
      			Serial.print(F("  I2CAddress |  TempOffset   |  OTPmode  | SelectorMode  | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x14) {
      			Serial.print(F("         SlotConfig00        |       SlotConfig01        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x18) {
      			Serial.print(F("         SlotConfig02        |       SlotConfig03        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x1C) {
      			Serial.print(F("         SlotConfig04        |       SlotConfig05        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x20) {
      			Serial.print(F("         SlotConfig06        |       SlotConfig07        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x24) {
      			Serial.print(F("         SlotConfig08        |       SlotConfig09        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x28) {
      			Serial.print(F("         SlotConfig0A        |       SlotConfig0B        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x2C) {
      			Serial.print(F("         SlotConfig0C        |       SlotConfig0D        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x30) {
      			Serial.print(F("         SlotConfig0E        |       SlotConfig0F        | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j == 1) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x34) {
      			Serial.print(F("  UseFlag00  | UpdateCount00 | UseFlag01 | UpdateCount01 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x38) {
      			Serial.print(F("  UseFlag02  | UpdateCount02 | UseFlag03 | UpdateCount03 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x3C) {
      			Serial.print(F("  UseFlag04  | UpdateCount04 | UseFlag05 | UpdateCount05 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x40) {
      			Serial.print(F("  UseFlag06  | UpdateCount06 | UseFlag07 | UpdateCount07 | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		} else if (i == 0x44) {
      			Serial.print(F("                      LastKeyUse[0:3]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x48) {
      			Serial.print(F("                      LastKeyUse[4:7]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x4C) {
      			Serial.print(F("                      LastKeyUse[8:B]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x50) {
      			Serial.print(F("                      LastKeyUse[C:F]                    | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				Serial.print(F("   "));
      			}
      			Serial.println();
      		} else if (i == 0x54) {
      			Serial.print(F("  UserExtra  |    Selector   | LockValue |  LockConfig   | "));
      			for (int j=0; j<4; j++) {
      				if (rx_buffer[SHA204_BUFFER_POS_DATA+j] < 0x10) {
      					Serial.print('0'); // Because Serial.print does not 0-pad HEX
      				}
      				Serial.print(rx_buffer[SHA204_BUFFER_POS_DATA+j], HEX);
      				if (j < 3) {
      					Serial.print(F(" | "));
      				} else {
      					Serial.print(F("   "));
      				}
      			}
      			Serial.println();
      		}
      	}
      #endif // not USE_SOFT_SIGNING
      }
      
      /** @brief Sketch setup code */
      void setup()
      {
      	// Delay startup a bit for serial consoles to catch up
      	unsigned long enter = hwMillis();
      	while (hwMillis() - enter < (unsigned long)500);
      #ifndef USE_SOFT_SIGNING
      	uint8_t tx_buffer[SHA204_CMD_SIZE_MAX];
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	uint8_t lockConfig = 0;
      	uint8_t lockValue = 0;
      	uint16_t crc;
      	(void)crc;
      #else
      	// initialize pseudo-RNG
      	randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN));
      #endif
      	uint8_t key[32];
      	(void)key;
      
      	Serial.begin(115200);
      	hwInit();
      	Serial.println(F("Personalization sketch for MySensors usage."));
      	Serial.println(F("-------------------------------------------"));
      
      #ifndef USE_SOFT_SIGNING
      	// Wake device before starting operations
      	ret_code = sha204.sha204c_wakeup(rx_buffer);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to wake device. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	}
      	// Read out lock config bits to determine if locking is possible
      	ret_code = sha204.sha204m_read(tx_buffer, rx_buffer, SHA204_ZONE_CONFIG, 0x15<<2);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Failed to determine device lock status. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		lockConfig = rx_buffer[SHA204_BUFFER_POS_DATA+3];
      		lockValue = rx_buffer[SHA204_BUFFER_POS_DATA+2];
      	}
      #endif
      
      #ifdef STORE_SOFT_KEY
      #ifdef USER_SOFT_KEY
      	memcpy(key, user_soft_key_data, 32);
      	Serial.println(F("Using this user supplied soft HMAC key:"));
      #else
      	// Retrieve random value to use as soft HMAC key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 32; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft HMAC key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_KEY
      	Serial.print("#define MY_SOFT_HMAC_KEY ");
      	for (int i=0; i<32; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 31) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32);
      #endif // STORE_SOFT_KEY
      
      #ifdef STORE_SOFT_SERIAL
      #ifdef USER_SOFT_SERIAL
      	memcpy(key, user_soft_serial, 9);
      	Serial.println(F("Using this user supplied soft serial:"));
      #else
      	// Retrieve random value to use as serial
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 9; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random serial generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 9);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This value will be stored in EEPROM as soft serial:"));
      	} else {
      		Serial.println(F("Serial is not randomized (configuration not locked):"));
      	}
      #endif // not USE_SOFT_SIGNING
      #endif // not USER_SOFT_SERIAL
      	Serial.print("#define MY_SOFT_SERIAL ");
      	for (int i=0; i<9; i++) {
      		Serial.print("0x");
      		if (key[i] < 0x10) {
      			Serial.print('0'); // Because Serial.print does not 0-pad HEX
      		}
      		Serial.print(key[i], HEX);
      		if (i < 8) {
      			Serial.print(',');
      		}
      	}
      	Serial.println();
      	hwWriteConfigBlock((void*)key, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9);
      #endif // STORE_SOFT_SERIAL
      
      #ifdef STORE_AES_KEY
      #ifdef USER_AES_KEY
      	memcpy(key, user_aes_key, 16);
      	Serial.println(F("Using this user supplied AES key:"));
      #else
      	// Retrieve random value to use as key
      #ifdef USE_SOFT_SIGNING
      	for (int i = 0; i < 16; i++) {
      		key[i] = random(256) ^ micros();
      		unsigned long enter = hwMillis();
      		while (hwMillis() - enter < (unsigned long)2);
      	}
      	Serial.println(F("This key will be stored in EEPROM as AES key:"));
      #else
      	ret_code = sha204.sha204m_random(tx_buffer, rx_buffer, RANDOM_SEED_UPDATE);
      	if (ret_code != SHA204_SUCCESS) {
      		Serial.print(F("Random key generation failed. Response: "));
      		Serial.println(ret_code, HEX);
      		halt();
      	} else {
      		memcpy(key, rx_buffer+SHA204_BUFFER_POS_DATA, 32);
      	}
      	if (lockConfig == 0x00) {
      		Serial.println(F("This key will be stored in EEPROM as AES key:"));
      	} else {
      		Serial.println(F("Key is not randomized (configuration not locked):"));
      	}
      	
      .... i have cut the rest of code because its to long to post here complete ...
      
      

      but i dont get any output on serial monitor. Do you know whaat is went wrong?
      thanks

      posted in OpenHardware.io
      meddie
    • RE: Encryption, Signing and OTA is there any how-to?

      if i understood it correctly, i have to use the securitypersonalization.ino on the gw. For the first time i upload this code

      /**
       * @def LOCK_CONFIGURATION
       * @brief Uncomment this to enable locking the configuration zone.
       *
       * It is still possible to change the key, and this also enable random key generation.
       * @warning BE AWARE THAT THIS PREVENTS ANY FUTURE CONFIGURATION CHANGE TO THE CHIP
       */
      #define LOCK_CONFIGURATION
      
      /**
       * @def LOCK_DATA
       * @brief Uncomment this to enable locking the data zone.
       *
       * It is not required to lock data, key cannot be retrieved anyway, but by locking
       * data, it can be guaranteed that nobody even with physical access to the chip,
       * will be able to change the key.
       * @warning BE AWARE THAT THIS PREVENTS THE KEY TO BE CHANGED
       */
      //#define LOCK_DATA
      
      /**
       * @def SKIP_KEY_STORAGE
       * @brief Uncomment this to skip key storage (typically once key has been written once)
       */
      #define SKIP_KEY_STORAGE
      
      /**
       * @def USER_KEY
       * @brief Uncomment this to skip key generation and use @ref user_key_data as key instead.
       */
      //#define USER_KEY
      
      /**
       * @def SKIP_UART_CONFIRMATION
       * @brief Uncomment this for boards that lack UART
       *
       * @b Important<br> No confirmation will be required for locking any zones with this configuration!
       * Also, key generation is not permitted in this mode as there is no way of presenting the generated key.
       */
      //#define SKIP_UART_CONFIRMATION
      
      /**
       * @def USE_SOFT_SIGNING
       * @brief Uncomment this to store data to EEPROM instead of ATSHA204A
       */
      //#define USE_SOFT_SIGNING
      
      /**
       * @def STORE_SOFT_KEY
       * @brief Uncomment this to store soft HMAC key to EEPROM
       */
      //#define STORE_SOFT_KEY
      
      /**
       * @def USER_SOFT_KEY
       * @brief Uncomment this to skip soft HMAC key generation and use @ref user_soft_key_data as HMAC key instead.
       */
      //#define USER_SOFT_KEY
      
      /**
       * @def STORE_SOFT_SERIAL
       * @brief Uncomment this to store soft serial to EEPROM
       */
      //#define STORE_SOFT_SERIAL
      
      /**
       * @def USER_SOFT_SERIAL
       * @brief Uncomment this to skip soft serial generation and use @ref user_soft_serial as serial instead.
       */
      //#define USER_SOFT_SERIAL
      
      /**
       * @def STORE_AES_KEY
       * @brief Uncomment this to store AES key to EEPROM
       */
      //#define STORE_AES_KEY
      
      /**
       * @def USER_AES_KEY
       * @brief Uncomment this to skip AES key generation and use @ref user_aes_key as key instead.
       */
      //#define USER_AES_KEY
      
      

      When its uploaded on first run i will get the AES and HMAC Key, which i have to notice and safe securely.

      Then i have to upload the sketch again with this code:

      /**
       * @def LOCK_CONFIGURATION
       * @brief Uncomment this to enable locking the configuration zone.
       *
       * It is still possible to change the key, and this also enable random key generation.
       * @warning BE AWARE THAT THIS PREVENTS ANY FUTURE CONFIGURATION CHANGE TO THE CHIP
       */
      #define LOCK_CONFIGURATION
      
      /**
       * @def LOCK_DATA
       * @brief Uncomment this to enable locking the data zone.
       *
       * It is not required to lock data, key cannot be retrieved anyway, but by locking
       * data, it can be guaranteed that nobody even with physical access to the chip,
       * will be able to change the key.
       * @warning BE AWARE THAT THIS PREVENTS THE KEY TO BE CHANGED
       */
      //#define LOCK_DATA
      
      /**
       * @def SKIP_KEY_STORAGE
       * @brief Uncomment this to skip key storage (typically once key has been written once)
       */
      //#define SKIP_KEY_STORAGE
      
      /**
       * @def USER_KEY
       * @brief Uncomment this to skip key generation and use @ref user_key_data as key instead.
       */
      #define USER_KEY
      
      /**
       * @def SKIP_UART_CONFIRMATION
       * @brief Uncomment this for boards that lack UART
       *
       * @b Important<br> No confirmation will be required for locking any zones with this configuration!
       * Also, key generation is not permitted in this mode as there is no way of presenting the generated key.
       */
      #define SKIP_UART_CONFIRMATION
      
      /**
       * @def USE_SOFT_SIGNING
       * @brief Uncomment this to store data to EEPROM instead of ATSHA204A
       */
      //#define USE_SOFT_SIGNING
      
      /**
       * @def STORE_SOFT_KEY
       * @brief Uncomment this to store soft HMAC key to EEPROM
       */
      //#define STORE_SOFT_KEY
      
      /**
       * @def USER_SOFT_KEY
       * @brief Uncomment this to skip soft HMAC key generation and use @ref user_soft_key_data as HMAC key instead.
       */
      //#define USER_SOFT_KEY
      
      /**
       * @def STORE_SOFT_SERIAL
       * @brief Uncomment this to store soft serial to EEPROM
       */
      //#define STORE_SOFT_SERIAL
      
      /**
       * @def USER_SOFT_SERIAL
       * @brief Uncomment this to skip soft serial generation and use @ref user_soft_serial as serial instead.
       */
      //#define USER_SOFT_SERIAL
      
      /**
       * @def STORE_AES_KEY
       * @brief Uncomment this to store AES key to EEPROM
       */
      #define STORE_AES_KEY
      
      /**
       * @def USER_AES_KEY
       * @brief Uncomment this to skip AES key generation and use @ref user_aes_key as key instead.
       */
      //#define USER_AES_KEY
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY)
      #error You have to define USER_KEY for boards that does not have UART
      #endif
      
      #ifdef USER_KEY
      /** @brief The user-defined HMAC key to use for personalization */
      #define MY_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store in key slot 0 */
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_KEY
      /** @brief The user-defined soft HMAC key to use for EEPROM personalization */
      #define MY_SOFT_HMAC_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft HMAC key in EEPROM */
      const uint8_t user_soft_key_data[32] = {MY_SOFT_HMAC_KEY};
      #endif
      
      #ifdef USER_SOFT_SERIAL
      /** @brief The user-defined soft serial to use for EEPROM personalization */
      #define MY_SOFT_SERIAL 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as soft serial in EEPROM */
      const uint8_t user_soft_serial[9] = {MY_SOFT_SERIAL};
      #endif
      
      #ifdef USER_AES_KEY
      /** @brief The user-defined AES key to use for EEPROM personalization */
      #define MY_AES_KEY 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
      /** @brief The data to store as AES key in EEPROM */
      const uint8_t user_aes_key[16] = {MY_AES_KEY};
      #endif
      
      

      in the second code i have to place the Keys which i got on first run.

      after this i can upload the normally gateway sketch

      is that correct?
      thank you very much

      posted in General Discussion
      meddie
    • RE: Encryption, Signing and OTA is there any how-to?

      ok, i did read this three times but i dont understand.

      posted in General Discussion
      meddie
    • Encryption, Signing and OTA is there any how-to?

      Hi,

      i would like to place any sensors at my home, but it should be signed and encrypted. On the website are a lot of builds but noone describes how to setup the encryption and signing.
      OTA too.

      is there something like a how-to or a description how to setup?
      Thanks a lot!

      posted in General Discussion
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Hi,
      i did it! The gateway has worked fine all the time! When i have uploaded the GatewayW5100 Sketch and connected the Eternet Module and the NRF24 Modul, then i didnt get anythin on Serial Monitor but i think its correct so, because FHEM (my Controller) shows me that the Sensebender Gateway is connected and added one new Device.

      Then i tried to upload the Sketch from second post, and get some errors, i had to delete this Line
      #include <drivers/ATSHA204/ATSHA204.cpp>

      then i could compile and upload the sketch but i get three warnings:

      c:/users/meddie/appdata/local/arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes

      c:/users/meddie/appdata/local/arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes

      c:/users/meddie/appdata/local/arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld.exe: warning: changing start of section .bss by 4 bytes

      I dont know what this means, but it looks like the gateway is working. FHEM continues showing as connected!

      Do you know what this warning does mean?
      Thanks a lot!

      posted in Hardware
      meddie
    • RE: 💬 Sensebender Gateway

      i have only changed the ip adress
      here is the sketch:

      /**
       * The MySensors Arduino library handles the wireless radio link and protocol
       * between your home built sensors/actuators and HA controller of choice.
       * The sensors forms a self healing radio network with optional repeaters. Each
       * repeater and gateway builds a routing tables in EEPROM which keeps track of the
       * network topology allowing messages to be routed to nodes.
       *
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik EKblad
       * Contribution by a-lurker and Anticimex,
       * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
       * Contribution by Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 10,0,0,253   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      
      
      void setup()
      {
      }
      
      void loop()
      {
      }```
      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Gateway

      Ok i just connected the W5100 and NRF24 Module and uploaded the GatewayW5100 Sketch and when the upload is done after reset i dont get any output on serial monitor.
      The orange, green and red led are lighting.

      When i upload the SensebenderGatewaySerial then i get output on serial monitor. It think the problem must be the w5100. But what going wrong?

      posted in OpenHardware.io
      meddie
    • RE: 💬 Sensebender Gateway

      Hi tbowmo,

      with the gatewayw5100 Sketch i get every 10 seconds 5 lines output on serial monitor:
      The sketch is default i changed only the ip adress

      0;255;3;0;9;TSM:FAIL:RE-INIT
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;!TSM:INIT:TSP FAIL
      0;255;3;0;9;TSM:FAIL:CNT=3
      0;255;3;0;9;TSM:FAIL:PDT
      0;255;3;0;9;TSM:FAIL:RE-INIT
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;!TSM:INIT:TSP FAIL
      0;255;3;0;9;TSM:FAIL:CNT=4
      0;255;3;0;9;TSM:FAIL:PDT
      0;255;3;0;9;TSM:FAIL:RE-INIT
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;!TSM:INIT:TSP FAIL
      0;255;3;0;9;TSM:FAIL:CNT=5
      0;255;3;0;9;
      
      

      i dont know why, but i just uploaded the sensebenderserialgateway sketch and now i get this output:

      0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGS--,VER=2.1.1
      0;255;3;0;9;TSF:LRT:OK
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSF:WUR:MS=0
      0;255;3;0;9;TSM:INIT:TSP OK
      0;255;3;0;9;TSM:INIT:GW MODE
      0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
      0;255;3;0;9;MCO:REG:NOT NEEDED
      0;255;3;0;14;Gateway startup complete.
      0;255;0;0;18;2.1.1
      0;255;3;0;9;MCO:BGN:STP
      0;255;3;0;9;
      

      the NRF Module is connected! Now i need to get the w5100 module to work.

      posted in OpenHardware.io
      meddie
    • RE: German users

      @tbowmo 👍

      posted in General Discussion
      meddie
    • RE: German users

      Ah cool! Freut mich! Was habt Ihr an MySensors alles im Einsatz?
      Cool! what are you using of mysensors?

      posted in General Discussion
      meddie
    • RE: 💬 Sensebender Gateway

      Hi together,

      i have some questions to you! I bought a sensebender gateway and a w5100 Ethernet Modul, but i cant get it to work. When i upload the Gateway5100 Sketch and put my yip address in it, then the GW is booting up i get some Data on the serial port but i cant ping the configured ip address. Then i tried to config via DHCP and see that the GW dont get an IP Address.
      And when i connect the NRF24 Modul then it seems that the GW is not bootin up anymore because i dont get any data on serial port.
      i need your help. Thanks a lot in advance

      posted in OpenHardware.io
      meddie
    • German users

      Hello together,

      i would like to know if here some users from germany?

      Thanks a lot
      Greets Eddie

      posted in General Discussion
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Hi,
      me again, today i installed the arduino ide on a other pc and it works now i could compile and upload the sketch. But when i user the Gateway5100 Sketch and put as ip Adresse 172.16.0.25 i could not ping the gateway.
      Do i have to config the pins that connected to the ethernet modul? A similar problem i had with my nrf24 modul when i connect it the gateway dont start. (i dont get any data on the serial port)
      Thank you a lot!
      Greets Eddie

      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Ok, next problem:
      the sketch Gateway5100 can be compiled but i get an error on uploding them.

      I have a Win 10 PC, the GW is detected by os and in the device manager i can see a usb device Com Port 3. When i connect the GW to the PC and start the serial monitor i get some lines.

      I think the communication should work.

      This is the output:

      Arduino: 1.8.1 (Windows 10), Board: "Sensebender Gateway"
      
      C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\meddie\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\meddie\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\meddie\Documents\Arduino\libraries -fqbn=MySensors:samd:mysensors_gw_native -vid-pid=0X1209_0X6949 -ide-version=10801 -build-path C:\Users\meddie\AppData\Local\Temp\arduino_build_739214 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.openocd.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.9.0-arduino -prefs=runtime.tools.CMSIS.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.bossac.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0 -prefs=runtime.tools.avrdude.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8 -prefs=runtime.tools.CMSIS-Atmel.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0 -verbose C:\Program Files (x86)\Arduino\examples\MySensors\GatewayW5100\GatewayW5100.ino
      C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\meddie\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\meddie\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\meddie\Documents\Arduino\libraries -fqbn=MySensors:samd:mysensors_gw_native -vid-pid=0X1209_0X6949 -ide-version=10801 -build-path C:\Users\meddie\AppData\Local\Temp\arduino_build_739214 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.openocd.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.9.0-arduino -prefs=runtime.tools.CMSIS.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.bossac.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0 -prefs=runtime.tools.avrdude.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino8 -prefs=runtime.tools.CMSIS-Atmel.path=C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0 -verbose C:\Program Files (x86)\Arduino\examples\MySensors\GatewayW5100\GatewayW5100.ino
      Using board 'mysensors_gw_native' from platform in folder: C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4
      Using core 'arduino' from platform in folder: C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11
      WARNING: Spurious .mystools folder in 'MySensors' library
      Detecting libraries used...
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions  -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\sketch\GatewayW5100.ino.cpp" -o "nul"
      ..."C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions  -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI\SPI.cpp" -o "nul"
      Generating function prototypes...
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions  -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\sketch\GatewayW5100.ino.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\preproc\ctags_target_for_gcc_minus_e.cpp"
      "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\preproc\ctags_target_for_gcc_minus_e.cpp"
      Compiling sketch...
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\sketch\GatewayW5100.ino.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\sketch\GatewayW5100.ino.cpp.o"
      Compiling libraries...
      Compiling library "Ethernet"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\Dhcp.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Dhcp.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\Dns.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Dns.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\Ethernet.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Ethernet.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\EthernetClient.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetClient.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\EthernetServer.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetServer.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\EthernetUdp.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetUdp.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\utility\socket.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\utility\socket.cpp.o"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src\utility\w5100.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\utility\w5100.cpp.o"
      Compiling library "MySensors-master"
      Compiling library "Wire"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire\Wire.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Wire\Wire.cpp.o"
      Compiling library "SPI"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet\src" "-IC:\Program Files (x86)\Arduino\libraries\MySensors-master" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI" "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI\SPI.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\SPI\SPI.cpp.o"
      Compiling core...
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -DF_CPU=48000000L -DARDUINO=10801 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD  -D__SAMD21G18A__ -DUSB_VID=0x1209 -DUSB_PID=0x6949 -DUSBCON '-DUSB_MANUFACTURER="MySensors.org"' '-DUSB_PRODUCT="Sensebender GW"' "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.0.0/CMSIS/Device/ATMEL/" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\cores\arduino" "-IC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw" "C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw\variant.cpp" -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\core\variant.cpp.o"
      .......
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-ar" rcs  "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\core\core.a" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\core\USB\USBCore.cpp.o"
      Linking everything together...
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gcc"  "-LC:\Users\meddie\AppData\Local\Temp\arduino_build_739214" -Os -Wl,--gc-sections -save-temps  "-TC:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\variants\mysensors_gw/linker_scripts/gcc/flash_with_bootloader.ld" "-Wl,-Map,C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -o "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.elf" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\sketch\GatewayW5100.ino.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Dhcp.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Dns.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\Ethernet.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetClient.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetServer.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\EthernetUdp.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\utility\socket.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Ethernet\utility\w5100.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\Wire\Wire.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\libraries\SPI\SPI.cpp.o" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214\core\variant.cpp.o" -Wl,--start-group "-LC:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Lib/GCC/" -larm_cortexM0l_math -lm "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/core\core.a" -Wl,--end-group
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-objcopy" -O binary  "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.elf" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.bin"
      "C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom  "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.elf" "C:\Users\meddie\AppData\Local\Temp\arduino_build_739214/GatewayW5100.ino.hex"
      Multiple libraries were found for "Ethernet.h"
       Used: C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet
       Not used: C:\Program Files (x86)\Arduino\libraries\Ethernet
      Using library Ethernet at version 1.1.2 in folder: C:\Users\meddie\AppData\Local\Arduino15\packages\MySensors\hardware\samd\1.0.4\libraries\Ethernet 
      Using library MySensors-master at version 2.1.1 in folder: C:\Program Files (x86)\Arduino\libraries\MySensors-master 
      Using library Wire at version 1.0 in folder: C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\Wire 
      Using library SPI at version 1.0 in folder: C:\Users\meddie\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.11\libraries\SPI 
      Sketch uses 43960 bytes (16%) of program storage space. Maximum is 262144 bytes.
      An error occurred while uploading the sketch```
      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      AAAAAH! I am so stupid! I read all the Time SAM and didnt seen the D at the end. Sorry sorry sorry.
      Yes it works now!!!
      Thank you very much!

      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Oh, ok i did not installed them. Just in moment i install the arduino sam Boards (32-bits ARM Cortex.m3) Version 1.6.11
      is that correct?

      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      I have installed the 1.0.4 Version. But the Arduino IDE is 1.8.1

      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Hi,

      thank you for your answers! I tried the GatewayW5100 Sketch but i get an error

      C:\Users\Meddie\AppData\Local\Temp\arduino_build_19882\sketch\GatewayW5100.ino.cpp:1:21: fatal error: Arduino.h: No such file or directory
      
       #include <Arduino.h>
      
                           ^
      
      compilation terminated.
      
      exit status 1``````
      
      

      Where i have to pu the Arduino.h file?

      I have already copied the files from drivers folder to the arduino ide drivers folder and i copied the whole mysensors-master folder to the libraries folder in the arduino ide.

      I got this error only if i select the sensebender Gatewas as board, when i select arduino uno i can compile witheout errors.

      When i switch in the ide to the Sensebender GW Board i get this text in the console:

      The current selected board needs the core 'arduino:arduino' that is not installed.```
      posted in Hardware
      meddie
    • RE: Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Hi,

      yes i did it, but i hoped to find a ready sketch. But i didnt!

      I just puted from all the sketches i needed the parts of Code together. Could you please check, if my code would work correctly ot even i did some mistakes.

      Thanks a lot!

      /**
      * The MySensors Arduino library handles the wireless radio link and protocol
      * between your home built sensors/actuators and HA controller of choice.
      * The sensors forms a self healing radio network with optional repeaters. Each
      * repeater and gateway builds a routing tables in EEPROM which keeps track of the
      * network topology allowing messages to be routed to nodes.
      *
      * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
      * Copyright (C) 2013-2015 Sensnology AB
      * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
      *
      * Documentation: http://www.mysensors.org
      * Support Forum: http://forum.mysensors.org
      *
      * This program is free software; you can redistribute it and/or
      * modify it under the terms of the GNU General Public License
      * version 2 as published by the Free Software Foundation.
      *
      *******************************
      *
      * REVISION HISTORY
      * Version 1.0 - Henrik EKblad
      * Contribution by a-lurker and Anticimex,
      * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
      * Contribution by Tomas Hozza <thozza@gmail.com>
      *
      *
      * DESCRIPTION
      * The EthernetGateway sends data received from sensors to the ethernet link.
      * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
      *
      * This GW code is designed for Sensebender GateWay / (Arduino Zero variant)
      *
      * Wire connections (OPTIONAL):
      * - Inclusion button should be connected to SW2
      *
      * LEDs on board (default assignments):
      * - Orange: USB RX/TX - Blink when receiving / transmitting on USB CDC device
      * - Yellow: RX  - Blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
      * - Green : TX  - Blink fast on radio message transmitted. In inclusion mode will blink slowly
      * - Red   : ERR - Fast blink on error during transmission error or recieve crc error
      * - Blue  : free - (use with LED_BLUE macro)
      *
      */
      
      #include <stdint.h>
      #include <pins_arduino.h>
      #define SKETCH_VERSION "0.2"
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_DEBUG_VERBOSE_SIGNING
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Set LOW transmit power level as default, if you have an amplified NRF-module and
      // power your radio separately with a good regulator you can turn up PA level.
      #define MY_RF24_PA_LEVEL RF24_PA_HIGH
      
      						
      #define MY_OTA_FIRMWARE_FEATURE
      
      #define MY_SIGNING_ATSHA204
      #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
      #define MY_SIGNING_REQUEST_SIGNATURES
      #ifndef MY_SIGNING_SOFT_RANDOMSEED_PIN
      #define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
      #endif															
      #ifndef MY_SIGNING_ATSHA204_PIN
      #define MY_SIGNING_ATSHA204_PIN 17
      #endif			  
      #define MY_RF24_ENABLE_ENCRYPTION
      	  
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 192,168,178,66   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      #define MY_INCLUSION_BUTTON_FEATURE
      
      // Inverses behavior of inclusion button (if using external pullup)
      //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
      
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Inverses the behavior of leds
      //#define MY_WITH_LEDS_BLINKING_INVERSE
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      #include <SD.h>
      #include <drivers/ATSHA204/ATSHA204.cpp>
      
      Sd2Card card;
      
      #define EEPROM_VERIFICATION_ADDRESS 0x01
      
      static uint8_t num_of_leds = 5;
      static uint8_t leds[] = {LED_BLUE, LED_RED, LED_GREEN, LED_YELLOW, LED_ORANGE};
      
      void setup()
      {
      	// Setup locally attached sensors
      }
      
      void presentation()
      {
      	// Present locally attached sensors
      }
      
      void loop()
      {
      	// Send locally attached sensor data here
      }
      
      
      void preHwInit()
      {
      
      	pinMode(MY_SWC1, INPUT_PULLUP);
      	pinMode(MY_SWC2, INPUT_PULLUP);
      	if (digitalRead(MY_SWC1) && digitalRead(MY_SWC2)) {
      		return;
      	}
      
      	uint8_t tests = 0;
      
      	for (int i=0; i< num_of_leds; i++) {
      		pinMode(leds[i], OUTPUT);
      	}
      	uint8_t led_state = 0;
      	if (digitalRead(MY_SWC1)) {
      		while (!Serial) {
      			digitalWrite(LED_BLUE, led_state);
      			led_state ^= 0x01;
      			delay(500);
      		} // Wait for USB to be connected, before spewing out data.
      	}
      	digitalWrite(LED_BLUE, LOW);
      	if (Serial) {
      		Serial.println("Sensebender GateWay test routine");
      		Serial.print("Mysensors core version : ");
      		Serial.println(MYSENSORS_LIBRARY_VERSION);
      		Serial.print("GateWay sketch version : ");
      		Serial.println(SKETCH_VERSION);
      		Serial.println("----------------------------------");
      		Serial.println();
      	}
      	if (testSha204()) {
      		digitalWrite(LED_GREEN, HIGH);
      		tests++;
      	}
      	if (testSDCard()) {
      		digitalWrite(LED_YELLOW, HIGH);
      		tests++;
      	}
      
      	if (testEEProm()) {
      		digitalWrite(LED_ORANGE, HIGH);
      		tests++;
      	}
      	if (testAnalog()) {
      		digitalWrite(LED_BLUE, HIGH);
      		tests++;
      	}
      	if (tests == 4) {
      		while(1) {
      			for (int i=0; i<num_of_leds; i++) {
      				digitalWrite(leds[i], HIGH);
      				delay(200);
      				digitalWrite(leds[i], LOW);
      			}
      		}
      	} else {
      		while (1) {
      			digitalWrite(LED_RED, HIGH);
      			delay(200);
      			digitalWrite(LED_RED, LOW);
      			delay(200);
      		}
      	}
      
      }
      
      bool testSha204()
      {
      	uint8_t rx_buffer[SHA204_RSP_SIZE_MAX];
      	uint8_t ret_code;
      	if (Serial) {
      		Serial.print("- > SHA204 ");
      	}
      	atsha204_init(MY_SIGNING_ATSHA204_PIN);
      	ret_code = atsha204_wakeup(rx_buffer);
      
      	if (ret_code == SHA204_SUCCESS) {
      		ret_code = atsha204_getSerialNumber(rx_buffer);
      		if (ret_code != SHA204_SUCCESS) {
      			if (Serial) {
      				Serial.println(F("Failed to obtain device serial number. Response: "));
      			}
      			Serial.println(ret_code, HEX);
      		} else {
      			if (Serial) {
      				Serial.print(F("Ok (serial : "));
      				for (int i=0; i<9; i++) {
      					if (rx_buffer[i] < 0x10) {
      						Serial.print('0'); // Because Serial.print does not 0-pad HEX
      					}
      					Serial.print(rx_buffer[i], HEX);
      				}
      				Serial.println(")");
      			}
      			return true;
      		}
      	} else {
      		if (Serial) {
      			Serial.println(F("Failed to wakeup SHA204"));
      		}
      	}
      	return false;
      }
      
      bool testSDCard()
      {
      	if (Serial) {
      		Serial.print("- > SD CARD ");
      	}
      	if (!card.init(SPI_HALF_SPEED, MY_SDCARD_CS)) {
      		if (Serial) {
      			Serial.println("SD CARD did not initialize!");
      		}
      	} else {
      		if (Serial) {
      			Serial.print("SD Card initialized correct! - ");
      			Serial.print("type detected : ");
      			switch(card.type()) {
      			case SD_CARD_TYPE_SD1:
      				Serial.println("SD1");
      				break;
      			case SD_CARD_TYPE_SD2:
      				Serial.println("SD2");
      				break;
      			case SD_CARD_TYPE_SDHC:
      				Serial.println("SDHC");
      				break;
      			default:
      				Serial.println("Unknown");
      			}
      		}
      		return true;
      	}
      	return false;
      }
      
      bool testEEProm()
      {
      	uint8_t eeprom_d1, eeprom_d2;
      	SerialUSB.print(" -> EEPROM ");
      	Wire.begin();
      	eeprom_d1 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
      	delay(500);
      	eeprom_d1 = ~eeprom_d1; // invert the bits
      	i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, eeprom_d1);
      	delay(500);
      	eeprom_d2 = i2c_eeprom_read_byte(EEPROM_VERIFICATION_ADDRESS);
      	if (eeprom_d1 == eeprom_d2) {
      		SerialUSB.println("PASSED");
      		i2c_eeprom_write_byte(EEPROM_VERIFICATION_ADDRESS, ~eeprom_d1);
      		return true;
      	}
      	SerialUSB.println("FAILED!");
      	return false;
      }
      
      bool testAnalog()
      {
      	int bat_detect = analogRead(MY_BAT_DETECT);
      	Serial.print("-> analog : ");
      	Serial.print(bat_detect);
      	if (bat_detect < 400 || bat_detect > 650) {
      		Serial.println(" Failed");
      		return false;
      	}
      	Serial.println(" Passed");
      	return true;
      }
      
      
      posted in Hardware
      meddie
    • Sensebender Gateway with NRF24 PA and Hardsigning and Encryption

      Hi together,

      i think i need some help, i have an old mysensor Ethernet Gateway i thin it Version 1.2. It is some time gone since i build it.
      But i didnt anything with the controller because i waited to the signing, ota and encryption.

      Now i bought the sensebender gateway and the w5100 ethernet modul. But wich sketch i should use.

      I dont understand, maybe somebody have some tips for me or maybe a complete sketch.
      Thanks a lot in advance.

      Greets Eddie

      posted in Hardware
      meddie
    • RE: W25X40CLSNIG as flash for OTA

      thank you very much, then i can order them. i was not sure.
      Greets Eddie

      posted in Hardware
      meddie
    • W25X40CLSNIG as flash for OTA

      Hey together,

      can i use this one W25X40CLSNIG as the flash module fot OTA?

      Thanks a lot.
      Greets Eddie

      posted in Hardware
      meddie
    • RE: Where to buy a flash for OTA (Germany)

      Yes i know, at the Digikey cost a flash chip 0.367€. 10 of them cost 3.67€ but additionaly 18€ for shipping.
      and with 21.67 cheaper then in amazon.

      posted in Hardware
      meddie
    • RE: Where to buy a flash for OTA (Germany)

      Danke aber bei Digikey kriege ich es dann sogar billiger. 3,67 + 18€ Versand.

      Is there some alternates reichelt, conrad, pollin or simillar.

      posted in Hardware
      meddie
    • Where to buy a flash for OTA (Germany)

      Hi,

      is here somebody from Germany and can say me where i can order some flash chips for OTA.
      I have found some on digikey but they want 18€ for shipping. The sippment period is not a problem i would order in china too, but on aliexpress i didnt found anything.

      Maybe someone of you can help.
      Thank you in advanced.
      Greets Eddie

      posted in Hardware
      meddie
    • RE: My Slim 2AA Battery Node

      when you are gonna to use some power up/down converter, them will need more power, so your battery will be faster empty.
      If you make your circuit so simple as possible, so you can reach the longest battery time.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @siod
      Attention this can damage your nrf24 Module.
      Greets Eddie

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @Soloam
      and a flash module for OTA Sketch Uploads 🙂

      posted in My Project
      meddie
    • RE: 💬 Very narrow and minimal switch node

      @GertSanders
      the PCB must be a little bit longer. But the two chips are not big. The ATSHA201A is very small its a 3 PIN smd chip, and the flash chip is 8 pin.

      posted in OpenHardware.io
      meddie
    • RE: 💬 Very narrow and minimal switch node

      Very nice! It would be perfect if it would get an atsha204a and a flash module.
      Greets Eddie

      posted in OpenHardware.io
      meddie
    • RE: New nrf24l01+ smd

      i like the first layou. Its just pretty narrow. ideal for housing in a cable duct. if there will be an atsha204, a flash modul and a battery sensor this would be the perfect node.

      posted in Hardware
      meddie
    • RE: My Slim 2AA Battery Node

      oh, yes. You have right, the battery fits in it, but its a little bit too big so i cant close the cover. Damn i didnt try it before.
      ok the i have to look for a graeter duct.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      What i like on this node is the great idea with the casing. To use a cable duct is a great idea. We have wooden windows and i found in a diy market cable ducts in wooden look
      like this:
      wooden look cable duct

      The Problem is that the size is 15x15 mm outside. inside the pcb can be max. 13 mm.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      it would be nice when a atsha204 a an a flash rom where placed to pcb for signing and ota

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      if you look to message Nr 179 you will find my bootloader and the correct fuses for this. But its a 1MHz Bootloader and the fuses too.
      Dont use it if you want to run it at 8 MHz.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      oh, yes! And you have to be carefully with them, because to set the fuses wrong, can destroy your µcontroller

      posted in My Project
      meddie
    • RE: Signing or encrypting the data

      yes me too. i will try my test setup to burn the bootloader at 8 mhz. It would make much easier.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @ahmedadelhosni
      fine, thank you in advanced

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @Anticimex

      one more question: is it possble to run the atmega with dualoptiboot bootloader at 1MHz. For battery use. And use the the encryption and signing and OTA.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @ahmedadelhosni
      Fine, please let stay me informed, because i am very interested too.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @Anticimex
      no, 100% safety wll never be possible. But i would feel me better when i know that the messages are not so easy readable for someone who has a mysensors too.
      I have some weeks ago read in the FHEM Forum, there has a user build a second gateway just for testing, and as he started them the whole sensors has sended the data twice to both gateways. The logical
      I didnt try this, but it's scary when it is so easy possible to read the sensors.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @Anticimex said:

      That depend on what bootloader you use. If you use MYSbootloader, then it won't work as it is the bootloader that manages the radio. But if you use dualoptiboot, the OTA solution is radio independent as the firmware is transferred in a "mysensors context" and stored on external flash before rebooting and then the dualoptiboot bootloader moves that firmware to internal flash. So with dualoptiboot, it should be possible to encrypt the data.

      OK, nice to hear that its possible. When i have to put an external flash and a dualoptibootloader, then its not the problem.

      But note that in both cases, signing won't be used for performance reasons.

      What do mean, i didnt understand. Can you explain this please.
      Thank you very much!
      Greets Eddie

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      Yes you have 100% right. I think the combination of signing and encrypting should be the better choice.

      But is IT right that ota wont work if encrypting?

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      please dont get angry with me, and correct if i am wrong. But when a sensor sends a message that a window is opened. And somebody can read this message then he konws that the window is not closed.

      When the message is signed then i know that the message is correct and comes from cerrect node. But the message is readable for "everyone" (is it right?)
      So everybody can read your sates. (is it right too?)
      When messages are singed and encrypted, then this anybody who can "listen" cant read the messages. He can still receive them but he cant start anything with them. He has only the info that one of the sensors has send data, but dont get the content of the data

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      OK, 100% safety you will never get, but its more safer then to send messages readable for everyone.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      I would preffer to sing and encrypt the messages. So it sure that the data is from correct node/controller, and is not faked. And encrypted and so not readable for third.
      But i would to use OTA too, and if i have correct understood, then its not possible. Because the bootloader needs the data unencrypted.
      Please correct me when i am false.
      i wish some how to's for dummies. Signing, Encrypting and OTA.
      It would be the perfect System, sure and future-proof.

      posted in General Discussion
      meddie
    • RE: Signing or encrypting the data

      @mfalkvidd said:

      It is all about the why. If the why is "I don't want other people to turn on and off my lights/lock/heat/stereo" the answer is not encryption.
      If the why is "I don't want someone dedicated to map my life to figure out when I'm home, what room I am in when I'm home, when I listen to music, what time I get up in the morning, etc" the answer is not encryption.

      If the why is "Because I want to be cool and I think encryption is makes me cool" then yes, the answer is encryption.

      OK, i thought, when encrypted, that nobody else can read the messages.
      I dont want be cool :-), i really want to be safe, that nobody can turn on/off anything, or read the states of my sensors to get the informations you wrote above.
      The sensors can give a really sensitive information. Because when somebody can read the states maybe he can recontruct your day. And then he knows exactly when you are not at home.

      posted in General Discussion
      meddie
    • Signing or encrypting the data

      Hi,

      i thin it is very important that the messages which will be send from nodes or from gateway are signed, or encrypted.
      Can somebody explain how to do this with the new api for beginners. I am not really good in this, and would be happy to get explained how to go on for dummies.
      Thank you
      Greets Eddie

      posted in General Discussion
      meddie
    • RE: My Slim 2AA Battery Node

      👍

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @ahmedadelhosni
      what is it on the door? is that a plastic wrap?

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @ahmedadelhosni said:

      @meddie THanks for the answer.

      Can you please also explain your final result to reach 4uA. I have also the same problem and current is 90uA and sometimes drops to 20uA, then rises again. Thanks.

      Edit: I figured out that I was using the 3.3v from arduino UNO. CHanged to two 1.5 batteries. THe current drops to 1.4uA when contact is open but sometimes it is also 15 uA. And when contact is closed it is 60 uA, and sometimes drops. Don't know why it is not stable.

      Edit 26.1.2016: I managed to reach 1.4uA with door opened, and 15uA when closed. I guess the problem was with the wiring. DOn't really know but I used a battery holder instead. I will try to rechange the resistor value to 1Mohm and reupdate.

      Edit 27.1.2016: ok I created another node and connected the contact sensor in series with the 1Mohm and the output is the voltage divider. now it is 1.4uA when open and 4.6uA when closed.

      Thanks

      Yes, i used a 1 Mohm reisitor instead of the internall pull up. You can read this few messages above. This was a tip from GertSander

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      Here

      @betonishard said:

      @meddie are you also using the optiboot 9600 NOBOD in boards.txt the same as in the first post (fuse settings I mean)? And are you using avrdude arduino ide for mac?

      Hi no i use the ide for Windows i dont have a mac.

      Here is the hex File

      :107E0000112484B714BE81FFE6D085E08093810001
      :107E100082E08093C00088E18093C10086E0809377
      :107E2000C20089E18093C4008EE0BFD0259A86E02D
      :107E300023EC3FEF91E0309385002093840096BBC4
      :107E4000B09BFECF1D9AA8958150A9F7EE24FF2480
      :107E5000AA24A394B5E0CB2EA1E1BA2EF3E0DF2E45
      :107E600098D0813461F495D0082FA5D0023829F13B
      :107E7000013811F485E001C083E083D07FC08234F3
      :107E800011F484E103C0853419F485E09CD076C0F8
      :107E9000853579F47ED0E82EFF247BD0082F10E0C2
      :107EA000102F00270E291F29000F111F84D07801E1
      :107EB00065C0863521F484E086D080E0DECF84364C
      :107EC00009F040C066D065D0082F63D080E0E81686
      :107ED00080E7F80618F4F701D7BEE895C0E0D1E0D6
      :107EE00058D089930C17E1F7F0E0EF16F0E7FF06A2
      :107EF00018F0F701D7BEE8955ED007B600FCFDCFBD
      :107F0000A701A0E0B1E02C9130E011968C9111977F
      :107F100090E0982F8827822B932B1296FA010C0160
      :107F2000A7BEE89511244E5F5F4FF1E0A038BF0770
      :107F300051F7F701C7BEE89507B600FCFDCFB7BE05
      :107F4000E8951CC0843761F424D023D0082F21D0B9
      :107F500032D0F70185917F0114D00150D1F70EC0C6
      :107F6000853739F428D08EE10CD085E90AD08FE02E
      :107F700084CF813511F488E018D01DD080E101D084
      :107F80006FCF982F8091C00085FFFCCF9093C600E3
      :107F900008958091C00087FFFCCF8091C00084FDD0
      :107FA00001C0A8958091C6000895E0E6F0E098E150
      :107FB000908380830895EDDF803219F088E0F5DF4B
      :107FC000FFCF84E1DECF1F93182FE3DF1150E9F7D5
      :107FD000F2DF1F910895282E80E0E7DFEE27FF27CC
      :027FE000099402
      :027FFE0000057C
      :0400000300007E007B
      :00000001FF
      

      Just create a new txt file put this code in there and rename the file to atmega328_1b.hex

      this is my boards.txt:

      ##############################################################
      
      atmega328_1mhz_4800baud.name=ATmega328 on a breadboard 1MHz internal clock, fast start, 1.8V BOD, 4800baud upload
      
      atmega328_1mhz_4800baud.upload.protocol=arduino
      atmega328_1mhz_4800baud.upload.maximum_size=32256
      atmega328_1mhz_4800baud.upload.speed=4800
      
      atmega328_1mhz_4800baud.bootloader.low_fuses=0x42
      atmega328_1mhz_4800baud.bootloader.high_fuses=0xDE
      atmega328_1mhz_4800baud.bootloader.extended_fuses=0x07
      
      atmega328_1mhz_4800baud.bootloader.file=atmega/atmega328_1b.hex
      atmega328_1mhz_4800baud.bootloader.unlock_bits=0x3F
      atmega328_1mhz_4800baud.bootloader.lock_bits=0x2F
      
      atmega328_1mhz_4800baud.build.mcu=atmega328p
      atmega328_1mhz_4800baud.build.f_cpu=1000000L
      atmega328_1mhz_4800baud.build.core=arduino:arduino
      atmega328_1mhz_4800baud.build.variant=arduino:standard
      
      
      atmega328_1mhz_4800baud.bootloader.tool=arduino:avrdude
      atmega328_1mhz_4800baud.upload.tool=arduino:avrdude
      

      this worked for me!

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      YEAH, YEAH YEAH! Thank you all for the help a big thanks to GertSanders. Now it seems to work perfectly. The current draw is now 4.6µa. Now i have to transfer from bredboard to pcb.
      Thank you very much!!!!!!

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      its the fuse, which defines the rising time. the oscillator needs some time to come to the correct frequency. If you dont wait this time its possble that your sketch dont work correctly. But the microcontroller is the 65 ms longer not in sleep mode and need more battery power. but works more stable.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node
      /**
       * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Interrupt driven binary switch example with dual interrupts
       * Author: Patrick 'Anticimex' Fallberg
       * Connect one button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
       * one in similar fashion on digital I/O pin 2.
       * This example is designed to fit Arduino Nano/Pro Mini
       * 
       */
      
      
      #include <MySensor.h>
      #include <SPI.h>
      
      #define SKETCH_NAME "Binary Sensor"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "0"
      
      #define PRIMARY_CHILD_ID 3
      #define SECONDARY_CHILD_ID 4
      
      #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
      #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
      
      #if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
      #error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
      #endif
      #if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
      #error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
      #endif
      #if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
      #error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
      #endif
      #if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
      #error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
      #endif
       
      MySensor sensor_node;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
      MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
      
      void setup()  
      {  
        sensor_node.begin();
      
        // Setup the buttons
        pinMode(PRIMARY_BUTTON_PIN, INPUT);
        pinMode(SECONDARY_BUTTON_PIN, INPUT);
      
        // Activate internal pull-ups
        digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
        digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
        
        // Send the sketch version information to the gateway and Controller
        sensor_node.sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER"."SKETCH_MINOR_VER);
      
        // Register binary input sensor to sensor_node (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        sensor_node.present(PRIMARY_CHILD_ID, S_DOOR);  
        sensor_node.present(SECONDARY_CHILD_ID, S_DOOR);  
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop() 
      {
        uint8_t value;
        static uint8_t sentValue=2;
        static uint8_t sentValue2=2;
      
        // Short delay to allow buttons to properly settle
        sensor_node.sleep(5);
        
        value = digitalRead(PRIMARY_BUTTON_PIN);
        
        if (value != sentValue) {
           // Value has changed from last transmission, send the updated value
           sensor_node.send(msg.set(value==HIGH ? 1 : 0));
           sentValue = value;
        }
      
        value = digitalRead(SECONDARY_BUTTON_PIN);
        
        if (value != sentValue2) {
           // Value has changed from last transmission, send the updated value
           sensor_node.send(msg2.set(value==HIGH ? 1 : 0));
           sentValue2 = value;
        }
      
        // Sleep until something happens with the sensor
        sensor_node.sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
      } ```
      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @GertSanders said:

      Makes sense to me. By closing the contact you get a path from 3V3 via the pullup resistor to ground.

      The current is (for a pullup resistor value around 30KOhm) arounda lot of 100uA.

      Try NOT using the internal pullup resistor of pin D3, and using an external pullup resistor of 1MOhm or more.

      You will see lower current when the contact is closed.

      Yesterday i get a lot of resistors, now i testen 1Mohm and the current draw is around 4 µa, but now the arduino do not recognize when the reedcontact is closed or open. When the contact is closed the current draw is 4 µa when opened 1.2µa
      do i have to edit the sketch in order to get it to work?

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @betonishard said:

      Hello all,

      I have been struggling with this for a couple of weeks now and I just can seem to figure out a good way to upload sketches to the arduio328p-pu. First of all I use this setup;

      I use arduino for mac 1.6.5
      I use a breadboard with a crystal, two capacitors and a resistor between reset and 5v.
      An arduino to burn bootloader (with the chip inserted and sketch arduinoISP uploaded).
      I use the same hex files as you guys with 1a. I used the optiboot 9600 BOD, just the 9600 and the 4800. Uploading the bootloader is no problem at all. Arduino ide burns the bootloader without any problems. However when I try to upload the sketches I get different errors. The “Yikes” version in which it states that my device signature is not ok and programmer not responding. I use upload using programmer.

      So, I tried to upload the arduino uno version to rule out all miscabling. So what I did was upload the arduino uno bootloader, tried to upload the blink sketch afterwards and it works. So my cables are ok….

      I thought to repeat the exact same process with the boot version above. However no succes, I keep getting stuck at uploading sketches. Is it just not possible?

      I read about setting the fuse options and I read that when you define these in the boards.txt, they will be set as the fuseparameters. When I check the boards txt above i see that fuse settings are: L0x62,H0xde,E0x07, however when I open the png file (first post, fuse settings) it states L0x62,H0xDE,E0xFF. Furthermore the lockbits are at 0xCF, compared to the boards.txt 0x2F. What is true and how should I set these. I don’t see a possibility in arduino ide (I use another arduino to upload, so I don’t have a tiny or USBASP.

      Help would be much appreciated here because I have like 30 boards sitting catching dust.

      Hi, i had the same problem, but then i tried the 1b hex and since i burned this it works for me.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      ok, i dont have 1mohm here. but i just ordered them. When i get them i will try out and will write here.
      Thynk you very much for your help.
      Great Forum! Great Projekt!
      Greets Eddie

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      yes of course, i just connected a nrf to the atmega an uploaded the binaryswitchsleepsensor sketch. Now i have a current draw 95.6µA
      But when i take the door contact off the atmega draws only 1.3µA
      When the door contact is closed (from 3 to GND) the the current is rising to 95.6µA

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      ok, i tried to burn with 0x07 Fuse. And i tried to power the atmega with 3.3 v and not 5v.
      Now i came down to 4µA in sleep mode with the lowpower sketch.
      When i try to flash a mysensors sketch the the atmega has a current draw 1mA.

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      @m26872 said:

      Do you "test the arduino alone" using MySensors lib and example sketches?

      Yes, on the bredboard is only the atmega 328p. nothing else. Connected to 5v

      Using Lowpower lib directly works ok as it seems.

      Yes using the LowPower lib i came down to 0.01mA current draw.

      Next step would be to connect the nRF24L01+ and run some MySensors lib example.

      Ok, i will try it today evening.

      Ext fuses 0x07 (BOD disabled) instead of 0x06 (BOD 1.8V) could save you a few uA.
      OK, i try this too.

      Thank you very much.
      Greets Eddie

      posted in My Project
      meddie
    • RE: My Slim 2AA Battery Node

      Hi together,

      as first i have to say, its a nice node, that you build.
      So i tried to build one. I ordered an atmega 328p. Flashed the bootloader from the forum. This is the boards.txt:

      atmega328_1mhz_4800baud.name=ATmega328 on a breadboard 1MHz internal clock, fast start, 1.8V BOD, 4800baud upload
      
      atmega328_1mhz_4800baud.upload.protocol=arduino
      atmega328_1mhz_4800baud.upload.maximum_size=32256
      atmega328_1mhz_4800baud.upload.speed=4800
      
      atmega328_1mhz_4800baud.bootloader.low_fuses=0x42
      atmega328_1mhz_4800baud.bootloader.high_fuses=0xDE
      atmega328_1mhz_4800baud.bootloader.extended_fuses=0x06
      
      atmega328_1mhz_4800baud.bootloader.file=atmega/atmega328_1b.hex
      atmega328_1mhz_4800baud.bootloader.unlock_bits=0x3F
      atmega328_1mhz_4800baud.bootloader.lock_bits=0x2F
      
      atmega328_1mhz_4800baud.build.mcu=atmega328p
      atmega328_1mhz_4800baud.build.f_cpu=1000000L
      atmega328_1mhz_4800baud.build.core=arduino:arduino
      atmega328_1mhz_4800baud.build.variant=arduino:standard
      
      
      atmega328_1mhz_4800baud.bootloader.tool=arduino:avrdude
      atmega328_1mhz_4800baud.upload.tool=arduino:avrdude
      

      Now i have measured the current draw, and the arduino alone draws 6.8mA (without crystal, nrf ...)
      I tried some sketches, (binaryswitchsleepsensor) but the current is not really gone down.
      The only sketch is this:

      // **** INCLUDES *****
      #include "LowPower.h"
      
      void setup()
      {
          // No setup is required for this library
      }
      
      void loop() 
      {
          // Enter power down state for 8 s with ADC and BOD module disabled
          LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);  
          
          // Do something here
          // Example: Read sensor, data logging, data transmission.
      }
      

      With this sketch is the current 0.02mA

      OK, 0.02mA is not bad, but when i read that some of you have few µa, i dont understand why the current on my atmega is so "high"

      Can somebody tell me what bootloader is good, wich fuses are good. And maybe what i have to do to get the current so small as possble

      Thank you very much
      Greets Eddie

      posted in My Project
      meddie
    • RE: Optical Window Sensor

      Hi hek,

      the sensors dont use a reedcontact to detect the window status, but an infrared distance sensor. This sensor dont need a magnet.
      Sorry i found only in german - this is the website of manufacturer:
      http://www.eq-3.de/sensoren-detail/items/homematic-funk-tuer-fensterkontakt-optisch.html

      And here you can see on youtube in action:
      HomeMatic Optischer Tür-/Fensterkontakt HM-Sec-SCo // Einbindung in FHEM // Howto // Tutorial – 03:29
      — virtualzone

      Greets Eddie

      posted in General Discussion
      meddie
    • Optical Window Sensor

      Hi togehter,

      have somebody build a sensor which works without a reedcontact. I mean an optical window sensor like a homematic?
      Thanky a lot
      Greets Eddie

      posted in General Discussion
      meddie
    • RE: Ethernet Gateway on Arduino nano

      the newest 1.5.1

      posted in Troubleshooting
      meddie