Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
3,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //Code for the www.MakeUseOf.com Wi-Fi connected Button tutorial by Ian Buckley
  2.  
  3. #include <IFTTTWebhook.h>
  4. #include <ESP8266WiFi.h>
  5.  
  6. #define ledPin 5
  7. #define wakePin 16
  8. #define ssid "YOUR SSID HERE"
  9. #define password "YOUR WIFI PASSWORD HERE"
  10. #define IFTTT_API_KEY "IFTTT_KEY_GOES_HERE"
  11. #define IFTTT_EVENT_NAME "IFTTT_EVENT_NAME_HERE"
  12.  
  13. void setup() {
  14. Serial.begin(115200);
  15. while(!Serial) {
  16. }
  17. Serial.println(" ");// print an empty line before and after Button Press
  18. Serial.println("Button Pressed");
  19. Serial.println(" ");
  20.  
  21. connectToWifi();
  22.  
  23. IFTTTWebhook hook(IFTTT_API_KEY, IFTTT_EVENT_NAME);
  24. hook.trigger();
  25.  
  26. pinMode(ledPin, OUTPUT);
  27. digitalWrite(ledPin, HIGH);
  28. delay(200);
  29. digitalWrite(ledPin, LOW);
  30.  
  31.  
  32.  
  33.  
  34. ESP.deepSleep(wakePin);
  35. }
  36.  
  37.  
  38. void connectToWifi() {
  39. Serial.print("Connecting to: NAME "); //uncomment next line to show SSID name
  40. //Serial.print(ssid);
  41. WiFi.begin(ssid, password);
  42. Serial.println(" ");
  43. Serial.print("Attempting to connect: ");
  44.  
  45. //try to connect for 10 seconds
  46. int i = 10;
  47. while(WiFi.status() != WL_CONNECTED && i >=0) {
  48. delay(1000);
  49. Serial.print(i);
  50. Serial.print(", ");
  51. i--;
  52. }
  53. Serial.println(" ");
  54.  
  55. //print connection result
  56. if(WiFi.status() == WL_CONNECTED){
  57. Serial.print("Connected.");
  58. Serial.println(" ");
  59. Serial.print("NodeMCU ip address: ");
  60. Serial.println(WiFi.localIP());
  61. }
  62. else{
  63. Serial.println("Connection failed - check your credentials or connection");
  64. }
  65. }
  66.  
  67.  
  68.  
  69. void loop(){
  70. //if deep sleep is working, this code will never run.
  71. Serial.println("This should never get printed");
  72. delay(1000);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement