Project Share - Low Power LoRA / Particle Gateway

@all,

I have been field testing my Particle / LoRA gateway system and ran into an interesting issue. I wonder if I might share the current solution and see if anyone has a better suggestion. the gateway keeps track of the nodes in the network and assigned them each a unique node number. More on this here:

One issue I have run across is that there is the possibility that two nodes could "claim" to have the same node number. I realized that I needed to have some way for a node to "prove" they owned a given node number. This does not happen often but it seemed like a prudent step.

One way to do this would be to ask the node to send its deviceID each time it reported data - this seemed a bit wasteful as the 24 digits of the deviceID do not change and LoRA messages are meant to be short. So, I decided to create a two hex digit "check sum" that was literally the sum of the 24 digits in the deviceID. With this approach, the nodes add the two digit checksum to their data reports instead of the whole deviceID. The checksum can have values from 0 to 360 and the chances of two nodes having the same checksum (1/360) and claiming the same node number (not common) should be fairly small. I feel like it is a good balance of efficiency and resiliency.

Obviously, this approach gets less effective as the number of node goes up but, then again, if the number of nodes goes up, the chance that two will claim the same node number go down. If someone out there is good with probabilities, it could probably be worked out.

Here is the code I use to take the deviceID (a string) and return the checksum (int). I looked for a more slick implementation using type conversions but did not find anything that would work. Suggestions welcome but this code does the job:

int stringCheckSum(String str){
    int result = 0;
    for(unsigned int i = 0; i < str.length(); i++){
      int asciiCode = (int)str[i];

      if (asciiCode >=48 && asciiCode <58) {              // 0-9
        result += asciiCode - 48;
      } 
      else if (asciiCode >=65 && asciiCode < 71) {        // A-F
        result += 10 + asciiCode -65;
      }
      else if (asciiCode >=97 && asciiCode < 103) {       // a - f
        result += 10 + asciiCode -97;
      }
    }
    return result;
}

Anyway, I hope this is helpful and comments / suggestions are welcome as always.

Thanks,

Chip