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 PASSWORD = “XXXXXXXXXX”;
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 = hardware.pin8.read();
if (buttonState == 0 && !throttle_protection) {
throttle_protection = true;
imp.wakeup(10, function() { // Release button and LED for user blinkup imp
throttle_protection = false;
hardware.pin9.configure(DIGITAL_IN);
});
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});
server.flush(5);
imp.setenroltokens(data.plan_id, data.id);
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
`