i installed joomla on my raspberry pi and use WiringPi to control the gpios.
I want a easy use of the gpios via joomla.
So i manipulate an existing joomla plugin for my use and it works fine
When i write {gpio}23{/gpio} in the editor of joomla it creates a a button on the homepage to toggle the pin
Here a screenshot:

But if i try to build my own plugin it does not work.
I can install the plugin but it has no effect.
The code of the xml file:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7" type="plugin" group="content">
<name>Raspberry Pi Gpio Toggle Plugin</name>
<author>mize03</author>
<creationDate>2012-11-21</creationDate>
<copyright></copyright>
<license></license>
<authorEmail></authorEmail>
<authorUrl></authorUrl>
<version>1.0</version>
<description>A plugin to toggle the gpios of the raspberry pi. example: {gpio}15{/gpio}</description>
<files>
<filename plugin="raspberryPiGpioTooglePlugin">raspberryPiGpioTooglePlugin.php</filename>
<filename>index.html</filename>
</files>
</extension>
Code: Select all
<?php
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class rasppigpio extends JPlugin {
public function onContentPrepare( $context, &$article, &$params, $limitstart=0 )
{
$txt = $article->text;
//check message to set a pin
if(isset($_POST['Button']))
{
if(substr($_POST['Button'], 0, 4) == "gpio")
{
shell_exec($_POST['Button']);
}
}
//replace all {gpio}NBR{/gpio} with a button
if(preg_match_all("@{gpio}(.*){/gpio}@Us", $article->text, $matches, PREG_PATTERN_ORDER) > 0)
{
foreach($matches[0] as $match)
{
$pos = strpos($articel->text, $match);
$pin_nbr = preg_replace("@{.+?}@", "", $match);
shell_exec("gpio -g mode $pin_nbr out");
$pin_status = trim(@shell_exec("gpio -g read $pin_nbr"));
$butt_text = "<FORM method=\"post\" action\"window.location.href\"
</td><button type=\"submit\" name=\"Button\"
value=\"gpio -g write $pin_nbr ".(($pin_status==0)?"1":"0")."\">".
"GPIO $pin_nbr: ".(($pin_status == 0) ? "LOW" : "HIGH")."</button></FORM>";
$txt = str_replace($match, $butt_text, $txt);
}
}
$article->text = $txt;
return true;
}
}
I dont understand why it works with the existing plugin!
Thank you for your help