Hi !
My current goal is simple:
Press Wio Terminal button A will open the Azure IoT Door, press B button will close the door.

A demo video is available here:
I already wrote about how to use the buttons, however, let’s refresh this.
Using Wio Terminal Buttons
We need to initialize the buttons, usually in setup(), and in the loop() we can check for the press status of each button.
void setup() {
Serial.begin(115200);
// init buttons
Serial.println("Init buttons");
pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
pinMode(WIO_KEY_C, INPUT_PULLUP);
}
void loop(){
if (digitalRead(WIO_KEY_A) == LOW)
{
Serial.println("[A] open door");
}
if (digitalRead(WIO_KEY_B) == LOW)
{
Serial.println("[B ] close door");
}
if (digitalRead(WIO_KEY_C) == LOW)
{
Serial.println("[C] refresh");
}
}
It’s easy, it follows the Arduino style.
Perform a HTTP Post to an Azure Function β‘from Wio Terminal
Now it’s time to make a HTTP POST to our Azure Function. I already wrote on how to perform a HTTP GET call. This is similar.
- This function is invoked from loop().
- Lines 3 to 20 are checking which button was pressed.
- Line 23 implement a routine to only call this every N seconds.
Important: the loop() will be executed several times per seconds. I don’t want N calls to the Azure Function. - Lines 27 to 43, perform the HTTP POST call and free resources.
void validateWioButtons(){
if (digitalRead(WIO_KEY_A) == LOW)
{
Serial.println("Button A Pressed, open door");
url = urlOpen;
performHttpPost = true;
}
if (digitalRead(WIO_KEY_B) == LOW)
{
Serial.println("Button B Pressed, close door");
url = urlClose;
performHttpPost = true;
}
if (digitalRead(WIO_KEY_C) == LOW)
{
Serial.println("[C] refresh");
lastTime = 0;
}
// validate last time http post call
if ((millis() - lastTimeHttpPost ) > timerDelayHttpPost) {
if(performHttpPost == true){
performHttpPost = false;
http.end();
http.setTimeout(3000);
http.begin(url);
int httpResponseCode = http.POST();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
lastTime = 0;
}
// update last time http post call
lastTimeHttpPost = millis();
performHttpPost = false;
}
}
One more time, this is super easy.
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
References
- Download Arduino IDE
- Wiki Seeed – Historgram
- Wiki Seeed β loading Images
- Wiki Seeed β Installing the File System Library
- Wiki Seed – Wifi Connectivity
- GitHub – Arduino_JSON
- Wikipedia – X BitMap
WioTerminal – Posts to interact with a Digital Twin Door πͺ with Azure IoT βοΈ and Azure Functions
- Convert and use images on the device
- 1st steps π£, developer steps
- Buttons and Charts time πππ
- Connecting to Wifi πΆ, display local IP and get ready for Azure βοΈ scenarios
- Getting JSON data from an Azure βοΈ Function
- Parsing JSON data from an Azure βοΈ Function
- Display a Digital Twin Door πͺ state using XBitmap with Azure IoT βοΈ
- Display a countdown progress bar π₯ for the next Azure IoT βοΈ refresh data call
- Open and close the Digital Twin Door πͺ using the Wio Terminal Buttons
- Training an π£οΈ audio recognition module. Record ποΈ audio samples forΒ training
- Training an π£οΈ audio recognition module. Edge Impulse for Arduino step-by-step and optimizations
- Training an π£οΈ audio recognition module. Running the model on the device
- Playing sound on the open and close events from the Digital Twin Door πͺ (coming soon)