Stap 7: Hoe google om e-mail te verzenden van Arduino via TEMBOO
Google om e-mail te verzenden van arduino via TEMBOO we iets moeten doen eerst.
[Google-Account nodig]
- Google-account maken [Maken Google-account]
- Een google App-specifieke wachtwoord die gegenereerd na 2-Step controle nodig. [Google App-specifieke wachtwoord instelling]
[Het gebruik van TEMBOO]
- Attatched TEMBOO library downloaden en installeren zoals als IRLED/Twitter bibliotheek naar de directory van de Arduino geïnstalleerd
- Maken TEMBOO accout eerste [TEMBOO accout]
- Er zijn veel API's al voorbereid door TEMBOO. We zullen "google e-mail" API gebruiken in dit project, dus we moeten gaan [Google > Gmail > SendEmail]
- [Belangrijke] En je moet kiezen "IoT modus [ON]" die is gelegen in de top/rechts met gele karakter.
- Test e-mail met fillout roze doos en klik op uitvoeren. (Zie afbeelding)
- Zien we de Arduino schets broncode voor verzenden gmail vanuit TEMBOO zoals hieronder
- Nu we gebruik van TEMBOO voor verzenden gmail maken kunnen
[Schets broncode]
/* Setup shield-specific #include statements */#include <SPI.h> #include <Dhcp.h> #include <Dns.h> #include <Ethernet.h> #include <EthernetClient.h> #include <Temboo.h> #include "TembooAccount.h" // Contains Temboo account informationbyte ethernetMACAddress[] = ETHERNET_SHIELD_MAC; EthernetClient client; int numRuns = 1; // Execution count, so this doesn't run forever int maxRuns = 10; // Maximum number of times the Choreo should be executedvoid setup() { Serial.begin(9600); // For debugging, wait until the serial console is connected. delay(4000); while(!Serial); Serial.print("DHCP:"); if (Ethernet.begin(ethernetMACAddress) == 0) { Serial.println("FAIL"); while(true); } Serial.println("OK"); delay(5000); Serial.println("Setup complete.\n"); } void loop() { if (numRuns <= maxRuns) { Serial.println("Running SendEmail - Run #" + String(numRuns++)); TembooChoreo SendEmailChoreo(client); // Invoke the Temboo client SendEmailChoreo.begin(); // Set Temboo account credentials SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); // Set Choreo inputs String MessageBodyValue = "Message what you want to send"; SendEmailChoreo.addInput("MessageBody", MessageBodyValue); String SubjectValue = "subject of email"; SendEmailChoreo.addInput("Subject", SubjectValue); String PasswordValue = "generated_password"; SendEmailChoreo.addInput("Password", PasswordValue); String UsernameValue = "youraccount"; SendEmailChoreo.addInput("Username", UsernameValue); String ToAddressValue = "destination_address SendEmailChoreo.addInput("ToAddress", ToAddressValue); // Identify the Choreo to run SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); // Run the Choreo; when results are available, print them to serial SendEmailChoreo.run(); while(SendEmailChoreo.available()) { char c = SendEmailChoreo.read(); Serial.print(c); } SendEmailChoreo.close(); } Serial.println("\nWaiting...\n"); delay(30000); // wait 30 seconds between SendEmail calls }
["TembooAccount.h", Header file]
/*IMPORTANT NOTE about TembooAccount.h TembooAccount.h contains your Temboo account information and must be included alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h, and copy this content into it. */ #define TEMBOO_ACCOUNT "your_temboo_account" // Your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // Your Temboo app key name #define TEMBOO_APP_KEY "1eb4e************************39a61" // Your Temboo app key #define ETHERNET_SHIELD_MAC {} /* The same TembooAccount.h file settings can be used for all Temboo SDK sketches. Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */