将NodeMCU连接到Microsoft Flow以发送电子邮件

时间:2019-03-22 16:52:52

标签: arduino nodemcu arduino-esp8266 microsoft-flow

我一直在努力让NodeMCU与Microsoft Flow进行通信。我希望能够在按下按钮时发送电子邮件。但是,按照本教程进行操作后,我仍然无法获取地址。如果我使用流URL并将其发布在地址栏中,则它可以正常工作,因此我不认为这是问题所在。请帮忙!

我必须从WiFiClientSecure.h库切换到WiFiClient.h库,因为“ client.connect(host,443)”永远不会恢复为真。 This is a Snip of my Flow

https://powerusers.microsoft.com/t5/Microsoft-Flow-Community-Blog/IoT-Button-Microsoft-Flow/ba-p/47011

#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 = 5;   // pushbutton connected to digital pin 0
int val = 0;     // variable to store the read value
//Include the SSL client
#include <WiFiClient.h>

char ssid[] = "My_SSID";       // your network SSID (name)
char password[] = "My_Password";  // your network key

//Add a SSL client
WiFiClient client;

//int ledPin = 2;

void setup() {
  //pinMode(ledPin, OUTPUT);
  //digitalWrite(ledPin, 1);

  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) {
    //digitalWrite(ledPin, 1);
    delay(500);
    //digitalWrite(ledPin, 0);
    Serial.print(".");
  }

  //digitalWrite( ledPin, 0);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();
  Serial.println(ip);

}

String MicrosoftFlow() {

  char host[] = "prod-51.westus.logic.azure.com";

  if (client.connect(host, 443)) {
    Serial.println("connected");

    String URL = "/workflows/f9f98afb10a14752b226d37fbffbad4a/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=epmkCBrYksnVnkzfjfvjen_PQ9Uk9oDzUiDrIvbjMuo";

    Serial.println(host);
    Serial.print("URL :"); Serial.println(URL);

    client.println(String("GET ") + URL + " HTTP/1.1");
    client.print("Host: "); client.println(host);
    client.println("User-Agent: arduino/1.0");
    client.println("");
    delay(10000);
  }
  else {
    Serial.println("Connection Failed.");
  }

}
void loop() {


  val = digitalRead(inPin);  // read input value
  delay(200);
  //Serial.println(val);

  if (val == HIGH) {
    Serial.println("BUTTON PRESSED");
    MicrosoftFlow();
    delay(1000);
    setup();
  }

}

0 个答案:

没有答案