Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Created September 12, 2018 10:27
Show Gist options
  • Save ElectricImpSampleCode/2e18b650bb6011dd00270e5aedc60c56 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/2e18b650bb6011dd00270e5aedc60c56 to your computer and use it in GitHub Desktop.
Electric Imp imp API imp.setrescuepin()
// To use a rescue pin, add the following function to your factory firmware
// and modify the pin and logic state as required
function setRescuePin() {
// Set up the rescue pin. We only need call this in our factory firmware
// if we are implementing a rescue pin, and this is why this function is
// not a part of our standard factory firmware example at
// https://developer.electricimp.com/examples/factoryfirmware
// Configure for impC001's pin G, set to go HIGH to trigger a rescue
imp.setrescuepin(hardware.pinG, 1);
}
// To use a rescue pin, replace the standard blessDeviceUnderTest() function
// with the following code
function blessDeviceUnderTest() {
// Run any tests you require for you DUT
local testSuccess = myTestFunction();
// Attempt to bless this device, and send the result to the Factory Test Results Webhook
server.bless(testSuccess, function(blessSuccess) {
// Send identifying info and result to the test results webhook
agent.send("test.result", { "device_id": hardware.getdeviceid(),
"success": (blessSuccess ? "SUCCEEDED" : "FAILED") });
// Clear the WiFi credentials and reboot if blessing completes successfully
if (blessSuccess) {
// Set connectivity for the new end-user's out-of-the-box experience
imp.clearconfiguration();
imp.setcountry(getRegionCode(WIFI_REGION));
// Set the rescue pin
setRescuePin();
// The imp will go idle at this point, allowing impOS to install
// application code and restart the Squirrel VM if the Production Device Group’s
// devices are set to receive application code immediately after blessing
// If you are installing your application upon device activation (first
// end-user BlinkUp), you can power down the device at this point
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment