Hi !

In today’s post I’ll share an scenario about:

Invoke an Azure Function to get JSON data

In my Digital Twin scenario, I got an Azure Function that returns the current state of a Digital Twin door. The response from the function is similar to this one:

{
    "state": 0,
    "desc": "closed",
    "source": "blog"
}

So, once the Wio Terminal has internet access, I can invoke the Azure Function and read the value with the door state. In example, for a door open state:

Wio Terminal Azure Function Response door closed

And for the door open:

Wio Terminal Azure Function Response door open

Important: The sample code is based on the work from Rui Santos, in the article [ESP32 HTTP GET and HTTP POST with Arduino IDE (JSON, URL Encoded, Text)].

I updated the code to work with the specific WiFi and HTTPClient libraries for the Wio Terminal.

Source Code

As usual, the full code is below and some notes

  • As mentioned before, this sample uses the Wio Terminal specific libraries for Wifi and HTTPClient libraries .
  • The request to the Azure Function for the IoT Door state will be performed every 10 seconds.
  • I added a couple of functions at the end of the ino file to display the information on the TFT screen.
  • In line 98 the HTTP GET process start. After reading the code for the HTTP Library, I realized that I need to define a timeout (3 seconds) and also invoke the end() function before init the http variable.

Now we are connected, so we can start to interact with Azure resources !

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


References


¿Con ganas de ponerte al día?

En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading