#include <SoftwareSerial.h> // SoftwareSerial mySerial(2, 3); // RX, TX rs323 int cnt = 0; // void setup() { mySerial.begin(115200); // mySerial.println("Halo world"); } void loop() { int lightValue = analogRead(A0); // int doorValue = analogRead(A1); // boolean light = false; boolean door = false; if(lightValue > 60) light = true; // 60 - . if(doorValue > 500) door = true; // 0, 1023. // , ... if(light && door) cnt++; // - else { if(cnt>0) { // mySerial.print("<"); mySerial.print(cnt); // mySerial.println(">"); } cnt = 0; // } delay(1000); }
<?php // $child_pid = pcntl_fork(); if ($child_pid) { exit(); } posix_setsid(); // include("post.php"); $filename = "/dev/ttyATH0"; // serial- $handle = fopen($filename, "r"); // while (!feof($handle)) { $sym = fread($handle, 1); // if($sym=='>') { $f=false; echo "<<$cnt>>\n"; flush(); act($cnt); $cnt=''; } elseif($sym=='<') $f=true; elseif($f) $cnt .= $sym; } fclose($handle); function act($time) { if($time<40) {echo "dunno\n";} if(40<=$time && $time<150) { postMyPost("i was pee");} if(150<=$time && $time<300) { postMyPost("i was poo");} if(300<=$time && $time<900) { postMyPost("i take shower");} } ?>
define('CONSUMER_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxx'); define('CONSUMER_SECRET', 'yyyyyyyyyyyyyyyyyyyyyyyyyy'); define('OAUTH_TOKEN', 'qwertyqwertyqwertyqwertyqwertyqwerty'); define('OAUTH_SECRET', 'sashagreysashagreysashagreysashagrey'); define('OAUTH_CALLBACK', 'http://example.com/twitteroauth/callback.php');
<?PHP require_once('lib/twitteroauth/twitteroauth.php'); require_once('lib/config.php'); function postMyPost($status) { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,OAUTH_TOKEN,OAUTH_SECRET); $connection->format = 'xml'; $connection->post('statuses/update', array('status'=>$status)); } ?>
root@OpenWrt:~# php-cgi /www/twitter/run.php X-Powered-By: PHP/5.4.11 Content-type: text/html root@OpenWrt:~#
root@OpenWrt:~# ps | grep run.php 1665 root 10436 S php-cgi /www/twitter/run.php 1670 root 1492 S grep run.php root@OpenWrt:~# kill 1665
Source: https://habr.com/ru/post/181852/
All Articles