Install software:
opkg update opkg install php5 php5-cli opkg install php5-mod-sockets opkg install php5-mod-json
Php code:
nano /mnt/sda1/bridge.php
#!/usr/bin/php-cli <?php require ("/usr/lib/php/bridge/bridgeclient.class.php"); $firstValue = $argv[1]; $secondValue = $argv[2]; $thirdValue = $argv[3]; $client = new bridgeclient(); $inputfile="/mnt/sda1/input.csv"; $inputstr=file_get_contents($inputfile); $inputstr="1,2,3"; $client->put("D12",$inputstr); $outputstr=$firstValue.','.$secondValue.','.$thirdValue; $outputfile="/mnt/sda1/output.csv"; file_put_contents($outputfile, $outputstr); ?>
chmod 755 /mnt/sda1/bridge.php
ATmega32u4 code:
#include <Process.h> void setup() { Bridge.begin(); while (!Serial); // do nothing until the serial monitor is opened Serial.println("Start"); } void loop() { Process p; p.begin("/mnt/sda1/bridge.php"); p.addParameter("4"); p.addParameter("5"); p.addParameter("6"); p.run(); char lbuffer[256]; Bridge.get("D12", lbuffer, 256); //Serial.println(lbuffer); String str = String(lbuffer); int commaIndex = str.indexOf(','); int secondCommaIndex = str.indexOf(',', commaIndex + 1); // Search for the next comma just after the first String firstValue = str.substring(0, commaIndex); String secondValue = str.substring(commaIndex + 1, secondCommaIndex); String thirdValue = str.substring(secondCommaIndex + 1); // To the end of the string Serial.println(firstValue); Serial.println(secondValue); Serial.println(thirdValue); delay(1000); }
Comments powered by CComment