Factory enrolment

So I’m following this guide: https://developer.electricimp.com/api/imp/setenroltokens on how to enrol my devices at the factory.

I’m a little unclear about the last step.

        if (success) {
            imp.setenroltokens(tokens.plan_id, tokens.id);
            // Don't do imp.clearconfiguration() here - we still want valid WiFi credentials to complete the enrol
            // After one second, production code will be downloaded and run

I waited about 10-20 seconds after seeing the green light appear on my board saying it was blessed successfully. However in ImpCentral the device was still showing unenrolled. It wasn’t until I power cycled the device did ImpCentral report that it had been enrolled but with the timestamp of when I power cycled it and not before during the factory blessing process.

So my question is does enrolment actually happen during the blessing process? Or are the tokens just saved and then down the road when it does connect will it enrol then. If that’s the case how long are the enrolment tokens valid for? If it sits in a warehouse for months before being used will they still be valid when it comes online for the first time and tries to enrol.

Finally instead of calling imp.clearconfiguration(); can I actually call imp.setwificonfiguration(); and set a different WiFi network instead of the one in the factory used for blessing? Or will it not download the production code onto the device if I set a WiFi configuration which isn’t available in the factory?

Just trying to clarify exactly what happens post blessing.


Is your code blocking at this point? You have to not be in an imp.sleep, infinite loop, etc - you have to return to idle to get the production code pushed.

Also, do you have “download production code at blessing” ticked in impCentral for this model?

Yeah ‘download production code at blessing’ is the chosen option in ImpCentral. The code idles as far as I’m aware. I have configured a UART interface. Do I need to call uart.disable() on that?

Out of interest, should the download and enrol work in test groups or just production? I tried in both with the same result but wanted to know for future tries.

No you don’t need to disable peripherals, that will happen when new code arrives and the VM is torn down. Paging @kevinhoiland on the test groups, I believe it should work though.

If you have detailed questions then file a ticket with device details and we can see what’s going on when you’re attempting this.

“Download production code after blessing” replaces the firmware with production code so it’s available for offline operation before blinkup/enrol. It doesn’t cause the device to enrol, however. You need imp.reset() to cause a cold boot and subsequent enrol.

Hi guys, indeed those device group settings work for both test zone and production zone :+1:

Thanks for the clarification Zandr!

Sorry for my delay, the page was to an older personal account :grinning: