// Created by: Akshaya Niraula // Date: 2016 December 15th. // Steps are valid as of 2016 December 15th. // 0) From Google spreadsheet, Tools > Script Editor... // 1) Write your code // 2) Save and give a meaningful name // 3) Run and make sure "doGet" is selected // You can set a method from Run menu // 4) When you run for the first time, it will ask // for the permission. You must allow it. // Make sure everything is working as it should. // 5) From Publish menu > Deploy as Web App... // Select a new version every time it's published // Type comments next to the version // Execute as: "Me (your email address)" // MUST: Select "Anyone, even anonymous" on "Who has access to this script" // For the first time it will give you some prompt, accept it. // You will need the given information (url) later. This doesn't change, ever! var number = "8001239999"; // your phone number var domain = "tmomail.net"; // You may find your domain for you carrier at: http://www.emailtextmessages.com/ var toEmail = "YourOrFriendsEmail@gmail.com"; function doGet(e){ Logger.log("--- doGet ---"); // for debugging if (e == null){e={}; e.parameters = {value:"-1"};} try{ // get the values from parameters to local var var value = e.parameters.value; var phoneEmail = number + "@" + domain; // Send Text Message (SMS) send_Email(phoneEmail, "NodeMCU here, your sensor went beyond your threshold. Sensor reported: " + value + " on:" + new Date()); // Send Email var message = "Dear User,

Your equipment has reached it's threshold value. It just reported a value of " + value + ". Please take a necessary action.
"; message += "As a valued customer, we have sent you a text message also.

"; message += "To learn more about this email, please click on the link below:
"; message += "www.Embedded-Lab.com


"; message += "Sincerely,
NodeMCU ESP8266"; send_Email(toEmail, message) return ContentService.createTextOutput("Things went successfully."); } catch(error) { Logger.log(JSON.stringify(error)); return ContentService.createTextOutput("oops...." + error.message + "\n" + new Date() + "\nnumber: " + number + + "\ndomain: " + domain); } } function send_Email(address, message){ MailApp.sendEmail({ "to": address, "subject": "Threshold reached - ESP8266", "htmlBody": message }); Logger.log("send_textMessage: " + "Email sent to: " + address); }