Advertisement
pleasedontcode

"WiFi Button" rev_01

Sep 27th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "WiFi Button"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-27 19:30:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* book meeting to the mail which is */
  21.     /* genesisestatesolutions@gmail.com by mailing the */
  22.     /* business name and city and its type */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  27. #include <FacebookApi.h>    //https://github.com/witnessmenow/arduino-facebook-api
  28. #include <ESP8266WiFi.h> // Include for WiFi functionality
  29. #include <WiFiClientSecure.h> // Include for secure WiFi client
  30. #include <SMTPClient.h> // Include for sending emails (make sure to have a suitable library for SMTP)
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void sendEmail(const String& businessName, const String& city, const String& type);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t ChatNow_PushButton_PIN_D2 = 2;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. // Initialize the EasyButton object with the pin number and default parameters
  42. EasyButton chatNowButton(ChatNow_PushButton_PIN_D2);
  43.  
  44. // Initialize WiFi client and Facebook API object
  45. WiFiClientSecure client;
  46. String FACEBOOK_ACCESS_TOKEN = "BIG_LONG_ACCESS_TOKEN"; // Replace with your actual access token
  47. FacebookApi api(client, FACEBOOK_ACCESS_TOKEN); // Initialize FacebookApi with client and access token
  48.  
  49. // SMTP client for sending emails
  50. SMTPClient smtpClient("smtp.example.com", "your_email@example.com", "your_email_password"); // Replace with your SMTP server and credentials
  51.  
  52. /****** FUNCTION DEFINITIONS *****/
  53. void setup(void)
  54. {
  55.     // Start serial communication for debugging
  56.     Serial.begin(115200);
  57.    
  58.     // Initialize the button
  59.     chatNowButton.begin();
  60.    
  61.     // Set the button pin mode to INPUT_PULLUP
  62.     pinMode(ChatNow_PushButton_PIN_D2, INPUT_PULLUP);
  63.    
  64.     // Connect to WiFi
  65.     WiFi.mode(WIFI_STA);
  66.     WiFi.disconnect();
  67.     delay(100);
  68.     Serial.print("Connecting to WiFi...");
  69.     WiFi.begin("your_ssid", "your_password"); // Replace with your actual SSID and password
  70.     while (WiFi.status() != WL_CONNECTED) {
  71.         delay(500);
  72.         Serial.print(".");
  73.     }
  74.     Serial.println("WiFi connected");
  75. }
  76.  
  77. void loop(void)
  78. {
  79.     // Read the button state
  80.     chatNowButton.read();
  81.  
  82.     // Check if the button is pressed
  83.     if (chatNowButton.isPressed()) {
  84.         // Define business details
  85.         String businessName = "Your Business Name"; // Replace with actual business name
  86.         String city = "Your City"; // Replace with actual city
  87.         String type = "Your Business Type"; // Replace with actual business type
  88.  
  89.         // Send email to book a meeting
  90.         sendEmail(businessName, city, type);
  91.     }
  92.  
  93.     // Example: Get total friends count
  94.     int friendsCount = api.getTotalFriends();
  95.     if (friendsCount >= 0) {
  96.         Serial.print("Facebook Friends: ");
  97.         Serial.println(friendsCount);
  98.     } else {
  99.         Serial.println("Error getting friends count");
  100.     }
  101. }
  102.  
  103. // Function to send email
  104. void sendEmail(const String& businessName, const String& city, const String& type) {
  105.     String subject = "Meeting Request from " + businessName;
  106.     String body = "Business Name: " + businessName + "\nCity: " + city + "\nType: " + type;
  107.  
  108.     // Send the email
  109.     if (smtpClient.send("genesisestatesolutions@gmail.com", subject, body)) {
  110.         Serial.println("Email sent successfully!");
  111.     } else {
  112.         Serial.println("Failed to send email.");
  113.     }
  114. }
  115.  
  116. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement