Skip to content

Instantly share code, notes, and snippets.

@ElectricImpSampleCode
Last active September 10, 2018 14:15
Show Gist options
  • Save ElectricImpSampleCode/d84392fadd92b8284a40 to your computer and use it in GitHub Desktop.
Save ElectricImpSampleCode/d84392fadd92b8284a40 to your computer and use it in GitHub Desktop.
A demonstration of server.setsendtimeoutpolicy()’s WAIT_FOR_ACK and WAIT_TIL_SENT options.
// Configure imp001 pin 1
hardware.pin1.configure(DIGITAL_OUT, 0);
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_FOR_ACK, 10);
data <- blob(4096);
state <- 0;
function blink() {
// Turn LED on or off
hardware.pin1.write(state);
// Write a message to the server
// (we append data to end to simulate sending lots data)
server.log(state.tostring() + data.tostring());
// Flip state
state = state == 0 ? 1 : 0;
// Call blink() with new state
imp.wakeup(0.01, blink);
}
// Start the loop
blink();
// Configure imp001 pin 1
hardware.pin1.configure(DIGITAL_OUT, 0);
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10);
data <- blob(4096);
state <- 0;
function blink() {
// Turn LED on or off
hardware.pin1.write(state);
// Write a message to the server
// (we append data to end to simulate sending lots data)
server.log(state.tostring() + data.tostring());
// Flip state
state = state == 0 ? 1 : 0;
// Call blink() with new state
imp.wakeup(0.01, blink);
}
// Start the loop
blink();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment