Last active
September 10, 2018 14:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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