deviceSet("/dev/ttyACM0"); // Set baud rate $serial->confBaudRate(9600); $serial->confParity("none"); $serial->confCharacterLength(8); $serial->confStopBits(1); $serial->confFlowControl("none"); // Open the device $serial->deviceOpen(); while(1){ $topics = array("recycle","plastic","ewaste", "environment","planet","global%20warming","prakriti", "risaikuru", "corruption", "earth"); $max = count($topics)-1; $index = rand(0 , $max ); $url = "http://data.tweetsentiments.com:8080/api/search.json?topic=".$topics[$index]; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); $result = curl_exec( $curl ); curl_close($curl); $result = utf8_encode($result); //var_dump($result); $data = json_decode($result, true); echo "tweets for ".$topics[$index]; // hat tip - http://www.bushveldlab.com/Bushveld_Labs/Blog/Entries/2011/3/13_Controlling_Arduino_with_PHP_in_Ubuntu.html // Nonzero number to be sent to Arduino $sentiment_index = intval($data["sentiment_index"]); $negative = intval($data["negative"]); $positive = intval($data["positive"]); $neutral = intval($data["neutral"]); echo $sentiment_index ."\n"; echo $positive."\n"; echo $negative."\n"; echo $neutral."\n"; $serial->sendMessage('s'); $serial->sendMessage(chr($sentiment_index)); $serial->sendMessage('p'); $serial->sendMessage(chr($positive)); $serial->sendMessage('g'); $serial->sendMessage(chr($negative)); $serial->sendMessage('n'); $serial->sendMessage(chr($neutral)); sleep(1800); } // Close the port $serial->deviceClose(); ?>