Production stopped - how to setenroltokens via factory agent?

We do end user blinkup in production with an imp001 that stopped blinking up correctly. An alternative is to set enroltokens via the factory agent, but I can not get it to work.

Logs show blessing is passed, and enrolment tokens are received from the server, and the agent try to pass it on to the device.

In the code below in function factorybless(), this works

agent.send("getConfig", {success = true});

but the previous

agent.on("config", function(data) {

seems never to be activated by the corresponding call from the agent.

I am sure it is related to this running as factory firmware somehow ?

const SSID = “XXXXXXXX”;
const FIXTURE_MAC = “XXXXXXXXXX”; // NOTE this format of this value

mac <- imp.getmacaddress();
deviceid <- hardware.getdeviceid();
bless_success <- false;
throttle_protection <- false;

function factoryblinkup() {
local buttonState =;
if (buttonState == 0 && !throttle_protection) {
throttle_protection = true;
imp.wakeup(10, function() { // Release button and LED for user blinkup imp
throttle_protection = false;
server.factoryblinkup(SSID, PASSWORD, hardware.pin9, BLINKUP_ACTIVEHIGH);
agent.send(“testresult”, {success = true});

function factorybless() {
server.log(“Device under test, Factorybless”);
server.bless(true, function(bless_success) {
server.log("Blessing " + (bless_success ? “PASSED” : “FAILED”));
if (bless_success == true){
imp.clearconfiguration(); // Prevents the device from reloading factory firmware
server.log(“Getting config …”);
agent.on(“config”, function(data) {
server.log(format(“Plan ID: %s, Enrollment Token: %s”, data.siteId data.token));
agent.send(“testresult”, {setenrolment = true});
imp.setwificonfiguration(data.ssid, data.password);
server.sleepfor(1); // Reboot to enable selftest in the appointed SW
agent.send(“getConfig”, {success = true});

if (imp.getssid() != SSID) return; // Don’t run the factory code if not in the factory
if (mac == FIXTURE_MAC) hardware.pin8.configure(DIGITAL_IN_PULLUP, factoryblinkup); // Factory imp button
else factorybless(); // Device under test


This line looks suspicious:

server.log(format("Plan ID: %s, Enrollment Token: %s", data.siteId data.token));

Is there a comma missing?

Thanks, it is from this example:

I removed it just now, as server.log’s don’t show up running as factory firmware anyway? Unfortunately it made no difference …

I though there was a comma missing, but Squirrel’s format() works with space-separated values too:

server.log(format("String: %s Integer: %i Float: %f", "one" 2 3.0));

logs as you’d expect:

String: one Integer: 2 Float: 3.000000

Who knew?

Did not get setenroltokens to work in factory firmware. I understand there will be a working code example on the web some time in the future.

So I am sticking with blinkup code now running again at half speed.