mcci-catena / Catena-Sketches

Top-level Arduino sketches for the MCCI Catena family of IoT LPWA Devices
MIT License
12 stars 21 forks source link

Need provisioning step-by-step guide #4

Open terrillmoore opened 7 years ago

terrillmoore commented 7 years ago

Provisioning is done in one of two ways:

Static (hard-wired in code) Provisioning

In this case, the programmer decides once and for all how a given CPU is going to be used. This is efficient but inflexible, and doesn't scale well, because all CPUs must be mentioned in a table. Still, for small projects this may be appropriate.

  1. Determine the SAMD21 CPUID using a test program.
  2. add the CPUID to SysEUI mapping in MCCI-Catena4410-Arduino-Library/src/lib/gk_WellKnownCpuBindings.cpp. This also defines the base platform to be used for this CPU.
  3. For LoRaWAN provisioning, create the keys (on The Things Network, use the console or use the ttnctl command.
  4. Copy the device-specific LoRaWAN keys to catena-lorawan-provisioning/extra/gk_lorawan_keys.project.cpp.

Dynamic (FRAM-based) Provisioining

If your platform contains a compatible FRAM chip (see, for example, the MCCI Catena 4450), you can dynamically provision your device using USB commands. There are two parts: setting up the FRAM so that the platform is correct, and setting up LoRaWAN.

Entering USB commands

USB provisioning commands are entered in the box at the top of the Arduino terminal. They can also be entered using any standard terminal program (e.g., TeraTerm). Commands are not echoed. Command lines may be terminated with carriage return or line feed.

The command parser will reply with one or more lines of text, separated by newline (line-feed) characters. The last line will either be "OK" (indicating success) or ? followed by an error code (for failure). If you get no response, you should assume that the command has not been executed.

The echo command can be used to check that the command parser is functioning. If you enter the command echo hello world, the program should display:

hello world
OK

Note: your terminal program might display something like:

hello world
                 OK

In this case, you should adjust the terminal program settings so that it displays "linefeed" as "cr-lf" or "newline".

Setting up the platform

If you're using a Feather M0 LoRa with added FRAM, use the sketch Catena4450m101_sensor1 to get started. Download it, and boot. The debug print will complain about not being configured. Don't worry yet.

  1. Determine the 64-bit SysEUI that you will use. If you don't have an IEEE OUI, you can generate a valid random SysEUI using https://github.com/things-nyc/random-eui64.
  2. Enter the following command in the Arduino terminal (using the input box at the top of the terminal screen). system configure syseuiyoursyseui (Change yoursyseui to the SysEUI you selected in step 1.)
  3. If you want your program to wait for USB before proceeding, say system configure operatingflags 0 Otherwise, if you want your program to boot up without waiting for USB, say system configure operatingflags 1
  4. Determine the platform GUID that best describes your system hardware configuration. For the Catena 4450 M101, use: system configure platformguid 82BF2661-70CB-45AE-B620-CAF695478BC1 For the Catena 4450 M102, use system configure platformguid 2281255E-AC5C-48CB-A263-9DC890D16638

Once the platform is set up, you don't have to change it unless you complete reset the FRAM contents.

Provisioning for LoRaWAN and The Things Network

This provisioning should be repeated whenever the network keys change. Both OTAA and ABP configuration are possible, however, we strongly recommend OTAA, and we leave application of ABP to the interested user.

  1. Use the procedure defined by your LoRaWAN network to assign a DevEUI, AppEUI and AppKey. MCCI recommends setting DevEUI the same as your SysEUI, but this is not mandatory; your network provider may require that you follow a different procedure. Also, if you're replacing a broken device, it may make sense to reuse the old DevEUI.
  2. Load the DevEUI using the following command: lorawan configure deveuithisDevEUI (Change thisDevEUI to the value determined in step 1.)
  3. Load the DevEUI using the following command: lorawan configure appeuimyAppEUI (Change myAppEUI to the value determined in step 1.)
  4. Load the AppKey using the following command: lorawan configure appkeythisAppKey (Change thisAppKey to the value determined in step 1.) Very important: don't use the same AppKey value for multiple devices, or you'll compromise the security of your device!
  5. Set OTAA mode: lorawan configure join 1
  6. Restart the Arduino. (Unfortunately, this has to be done manually.)

Reprovisioning

Reprovisioning is the same as provisioning, but you should add teh following commands to make sure all prior state is reset:

lorawan configure nwkskey 0
lorawan configure appskey 0
lorawan configure devaddr 0
lorawan configure netid 0

Then continue with provisioning as given above.

forrestfiller commented 6 years ago

@terrillmoore some dissonence between the updated readme and information provided here. For example, I was unable to complete the LoRaWAN provisioning section successfully--couldn't get my device registered to my application. However, once I found this issue, specifically the "Reprovisioning" section at the end of this issue, I entered in

lorawan configure nwkskey 0
lorawan configure appskey 0
lorawan configure devaddr 0
lorawan configure netid 0

And then the serial monitor went into a loop of EV_TXSTART, EV_TXSTART, etc.

Then I git cloned your random sysEUI generator here into my project dir, ran:

cc random-eui.c
./a.out

and grabbed the generated sysEUI printed in my terminal window. You reference it as a potential devEUI above, so on the TTN console I was able to change the devEUI there, and use the command from the above:

system configure syseui yoursyseui

in my serial monitor in atom via platformIO (which could be done in any terminal with cli installed):

pio device monitor --port /dev/cu.usbmodem1421 --baud 115200

then I ran through the LoRaWAN Provisioning commands from the README.md using the generated sysEUI as my devEUI, and now I'm finally seeing packets hitting my backend on TTN console.

This is a bit of a debug dump (sorry). I'm make a pull on your README, and hopefully you can cherry pick somethings that are useful to help people out.

Thanks for your support, excited to have the Catena4450 up and running via TTN.

forrestfiller commented 6 years ago

Another quick thing to consider adding into the README.md is the payload decoder option in the TTN console.

I dropped your code from your Catena message decoder for TTN into my decoder function on the TTN console and now I have lovely human readable data to view without converting hex in my brain - which I can't do thaaaaat well at this point anyway.

terrillmoore commented 6 years ago

Hm, the info here is better than some of the info in the README.md. Leaving this open in hopes that I'll remember to update the README. But we need to split up this repo (keep 4410 separate from 4450, etc.)