    //Serial.println(payload); 
    
    // Strip /sys/158293-433MhzBridge/devices/Switch- from string to obtain switch number   
-   int switchNumber;
-   sscanf(topic+sizeof(CLIENT_ID)/sizeof(char)+5+15, "%d", &switchNumber);
+   int switchNumber = switchNumberFromTopic(topic);
    if (switchNumber > 99) {
       return; 
    }


void loop() {
  client.loop();  // Mqtt loop
}

void publishRetained(char* topic, char* payload) {

byte ip[]     = { 192, 168, 8, 4 };
byte mqttServer[] = { 192, 168, 8, 2 };
Ws* firstSwitch = NULL;

RCSwitch wifiTransmitter = RCSwitch();
EthernetClient ethClient;
PubSubClient client(mqttServer, 1883, mqttReceive, ethClient);

unsigned int connCtr = 0;


void setup() {
  Serial.begin(9600);
  Serial.println("starting");
  pinMode(WIFIPIN, OUTPUT);
  wifiTransmitter.enableTransmit(WIFIPIN);

  Ethernet.begin(mac, ip);
   connectToMqttServer();
}


void connectToMqttServer() {
  Serial.println("Connecting to mqtt server");
    // clear switches
      Ws *next = firstSwitch;
      Ws *tmp;
       while(next) {
         tmp = next;
         next = next->next;
         free(tmp);  
       }
       firstSwitch = NULL;
   
  
  
    if (client.connect(CLIENT_ID)) {
    int s = sizeof(CLIENT_ID)/sizeof(char)+5+2;
    char sys[s];
    snprintf(sys, s, "/sys/%s/#",CLIENT_ID);
