Projekt liest Daten aus einer SQLite3 Datenbank (yun.db) mittels PHP Abfrage
und zeigt diese Werte tabellarisch im Webbrowser an.
/*
Project: TestGeofencing.ino
Author: Michael Gries
Creation: 2014-09-12
Modified: 2014-09-12
*/
#define AUTHOR "Michael Gries"
#define PROGRAM "TestGeofencing"
#define VERSION "14.9.12"
/*
Sending emails via Python script
ssh root@yourYunsName.local 'telnet localhost 6571'
NB: If you are using Windows, you must install a terminal emulator.
PuTTY is a reasonable choice, but you will have to enter the two commands above separately.
*/
/*
project-Reference http://yunadventures.blogspot.de/
http://asynkronix.se/internet-of-things-with-arduino-yun-and-yaler/
used Libraries: http://arduino.cc/en/Guide/Libraries
Bridge-Library http://arduino.cc/en/Reference/YunBridgeLibrary
SMTP-Reference https://docs.python.org/2/library/smtplib.html
Email examples https://docs.python.org/2/library/email-examples.html
*/
/*
required files on 'www' folder of this sketch directory:
pushmail.py
vaillant_logo.gif
vrc_status.txt (containing some ASCII characters only)
*/
/*
get example:
{"value":{"Email":"sended"},"response":"get"}
{"value":"michael","key":"author","response":"put"}
{"value":{"author":"michael","Email":"sended"},"response":"get"}
*/
#include
#include
#include
#include "Process.h"
YunServer server;
String sConsoleRead;
String sConsoleWrite;
String compiledfile=__FILE__;
String compileddate=__DATE__;
String compiledtime=__TIME__;
char frompython[33]; //data read from bridge that was put by python.
// Temporary storage before it is compied to a string.
// Allocate space for a 32 character long rest command
void setup() {
Bridge.begin();
Bridge.put("email","unsent");
Bridge.put("author",AUTHOR);
Bridge.put("program",PROGRAM);
Bridge.put("version",VERSION);
Console.begin();
// Wait for Console port to connect
while (!Console);
Console.println(">>>: Console active ...");
Console.print(PROGRAM); Console.print(" "); Console.println(VERSION);
Console.print(compiledfile); Console.print(compileddate); Console.println(compiledtime);
Console.println(" ");
Console.println("Open ssh session and run script");
Console.println("python /mnt/sd/arduino/www/TestSendingFileContentlViaPythonEmail/pushemail.py");
Console.println(" ");
Console.println("or use REST-API interface to request email by using following command:");
Console.println("http://gries.spdns.de/arduino/vrc");
Console.println(" ");
Console.println("or use REST-API interface to checking status:");
Console.println("http://gries.spdns.de/data/get");
Console.println(">>>");
server.listenOnLocalhost();
server.begin();
}
void loop() {
YunClient client = server.accept();
if (client) {
process(client);
client.stop();
}
//get the rest data from python
Bridge.get("email", frompython, 32);
String email=String(frompython);
}
void process(YunClient client) {
// RESP-API URL's are terminated with '\r\n' (i.e. two characters)
String command = client.readStringUntil('\r');
sConsoleRead = command;
Console.print("<<<: ");
Console.println(sConsoleRead);
// is "vrc" command?
if (command == "vrc") {
vrcCommand(client);
} else {
vrcError(client);
}
}
void vrcCommand(YunClient client) {
// Send feedback to client
sConsoleWrite = "VRC status requested - sending email to michael@gries.name";
sendEmail(sConsoleWrite);
Bridge.put("email","sended");
client.print(sConsoleWrite);
Console.print(">>>: ");
Console.println(sConsoleWrite);
}
void vrcError(YunClient client) {
// Send feedback to client
sConsoleWrite = "no valid request";
Bridge.put("email","unsent");
client.print(sConsoleWrite);
Console.print(">>>: ");
Console.println(sConsoleWrite);
}
void sendEmail(String subject) {
Process runSendEmail;
// Linino script
String scriptType = "python ";
String scriptPath = "/mnt/sda1/arduino/www/TestSendingFileContentlViaPythonEmail/";
String scriptName = "pushemail.py";
// Linino shell command running by Process
String shellCommand = scriptType + scriptPath + scriptName;
runSendEmail.runShellCommand(shellCommand);
while(runSendEmail.running());
Console.println(" ... runSendEmail script ended");
}
'20' && $isEntry) {
echo "It’s time to eat and switch on lights.\n";
// Integrate your e.g. house automation system here ...
// http_get("http://www.mypage.com/switchOnLights.html”);
}
?>