1

I know these type of "what's the best way" questions are frowned upon on StackExchange, but I will try to fit it within the guidelines. I have tried several methods and can't figure out which is the best to do this.

The Setup

I have a Pi (LAMP) networked to multiple Arduinos over I2C. I want to be able to click a button on a web page and operate a lights or take readings on the Arduino.

Progress

So far, I have found out how to use PHP to call change pins.

    //set the gpio's mode to output     
    system("gpio mode ".$pin." out");
    //reading pin's status
    exec ("gpio read ".$pin, $status, $return );
    //set the gpio to high/low
    if ($status[0] == "0" ) { $status[0] = "1"; }
    else if ($status[0] == "1" ) { $status[0] = "0"; }
    system("gpio write ".$pin." ".$status[0] );
    //reading pin's status
    exec ("gpio read ".$pin, $status, $return );
    //print it to the client on the response
    echo($status[0]);   
}

This works in changing the pins on the Pi itself.

Problem

I cannot translate this into an I2C call. I've tried to call a python script that uses SMBus, but I haven't been successful at getting it working. I've also looked at using Wiring Pi, but apparently there is an issue with calling data back into PHP.

I could use Javascript if this would be the best way. I've looked at using AJAX to make calls, and even considered if Node would be the best way. I am weakest with Javascript, but would learn if there is a developed library to achieve this goal.

In short, the question is what libraries or methods are there to execute I2C functions from a web page?

pekasus
  • 193
  • 8

0 Answers0