IoT Button: Process automation with Microsoft Flow using NodeMCU and Arduino IDE
In this article it will be developed an IoT button applied to the scenario of maintenance of a coffee machine using Microsoft Flow. However, it can be easily adapted to any other scenario or application.
Requirements
Setup Microsoft Flow Environment
1) Microsoft Flow portal
Access Microsoft Flow, log in and click "My Flows".
2) Create from blank
Click "Create from blank" to create a new workflow.
3) Request/Response
Give a name to your Flow. Select the Trigger "Request/Response".
4) Method GET
In "Advanced Options", choose "Method GET".
5) Add an action
Click "Add an action" to add a new action.
6) Send an email
Choose the action "Office 365 Outlook - Send an email".
7) Create Flow
Complete all required fields (as you wish), and then click "Create Flow".
😎 HTTP GET URL
Then copy and save the HTTP GET URL:
https://prod-32.westus.logic.azure.com:443/workflows/<ID>/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<ID>
Hardware Setup
1) Building a Circuit on Breadboard
Build the circuit like the one shown below.
Software
The ESP8266 NodeMcu comes with a firmware that lets you program the chip with the Lua scripting language. But if you are already familiar with the Arduino way of doing things, you can also use the Arduino IDE to progam the ESP. In this tutorial we'll use the Arduino IDE.
IDE Arduino setup
1) Package ESP8266
Download the IDE, and install it. Open the IDE; Choose File -> Preferences, in "Additional Boards Manager URLs" insert the URL "http://arduino.esp8266.com/stable/package_esp8266com_index.json" and than click "OK". After this steps, your download will start automatically. Once it is finished, restart the IDE.
Softaware Setup
Download the file "MicrosoftFlow_IoT_JoaoLucindo.zip" attached and replace the values:
By doing that, the final code will be:
#include <ESP8266WiFi.h> //static const uint8_t D0 = 16; //static const uint8_t D1 = 5; //static const uint8_t D2 = 4; //static const uint8_t D3 = 0; //static const uint8_t D4 = 2; //static const uint8_t D5 = 14; //static const uint8_t D6 = 12; //static const uint8_t D7 = 13; //static const uint8_t D8 = 15; //static const uint8_t D9 = 3; //static const uint8_t D10 = 1; int inPin = 16; // pushbutton connected to digital pin 0 int val = 0; // variable to store the read value //Include the SSL client #include <WiFiClientSecure.h> char ssid[] = "<SSID>"; // your network SSID (name) char password[] = "<PASSWORD>"; // your network key //Add a SSL client WiFiClientSecure client; void setup() { pinMode(inPin, INPUT); // sets the digital pin 1 as input Serial.begin(115200); // Set WiFi to station mode and disconnect from an AP if it was Previously // connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); // Attempt to connect to Wifi network: Serial.print("Connecting Wifi: "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); IPAddress ip = WiFi.localIP(); Serial.println(ip); } String MicrosoftFlow() { char host[] = "prod-37.westus.logic.azure.com"; if (client.connect(host, 443)) { Serial.println("connected"); String URL = "/workflows/<ID>/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<ID>"; Serial.println(URL); client.println("GET " + URL + " HTTP/1.1"); client.print("Host: "); client.println(host); client.println("User-Agent: arduino/1.0"); client.println(""); } } void loop() { val = digitalRead(inPin); // read input value delay(200); //Serial.println(val); if(val==HIGH){ MicrosoftFlow(); delay(1000); setup(); } }
Now you can compile and upload the code from your computer to the device. You can see the result (after press the push button) in the picture below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.