Go Down

Topic: Arduino yun Joomla SQL communications. (Read 14258 times) previous topic - next topic

chetto983

Thanks for the replay.

Unfortunately I can not access to my SQL because my provider don't give the grant from outside.
If I install on  arduino SQL I have problem to manage my dynamic internet IP.

My idea is one FTP connections (old style)

Folder:
TEMP_RX (  wryte from arduino to www)
RX ( data to be reed from WWW)

TEMP_TX ( WWW write to Arduino)
TX ( Arduino reed)

arduino send one TXT file whith one string ( RX (string code, 0000 ( file counter), 2013-12-30, 00 (temperature), .......)

WWW send other file whit thinks to do.

One tasks every minute check new file.

WWW every week delete old file.

I know this solutions are only one triks.

If you have other ideas please feel free to replay.




sonnyyu

You need webservice endpoints for Joomla/Mysql which use port 80 (WWW).

Webservice could be XMLRPC, RESTFul API, JSON...

Joomla has few XML-RPC plugins that let you do a few things, like the blogger API interface.
or you could create your own XML-RPC/RESTFul API/JSON plugin to do the custom things you want. The Yun side you need wrote webservice client with your favorite language ( very easy).


OttoF

Hello chetto983

the problem with the Dynamic IP can be to solve on this way ( I did it similar )
write a php skript
ip.php

Code: [Select]

<?php


$ip 
"UNBEKANNT";
    if (
$_SERVER["HTTP_CLIENT_IP"])
        
$ip $_SERVER["HTTP_CLIENT_IP"];
    else if(
$_SERVER["HTTP_X_FORWARDED_FOR"])
        
$ip $_SERVER["HTTP_X_FORWARDED_FOR"];
    else if(
$_SERVER["REMOTE_ADDR"])
        
$ip $_SERVER["REMOTE_ADDR"];

     
//echo "meine ip = ".$ip;

         
$fh fopen("home_ip.txt""w");
        if(
$fh==false)
            echo(
"unable to create file");
        
fputs ($fh$ip);
        
fclose ($fh);

?>




store this script in your homepage and call it from
arduino for example each minute.
On this way you can read your home ip from the file
home_ip.txt
on the hompage side by your provider.
open a route from your router at home to the ip from your arduino.
On this way you can connect to your datas at home.

chetto983

Godo Stuff ,
I collect all your informations and I will try use SQL on arduino.

Soon I have some working  code  I will share.

OttoF

#19
Dec 31, 2013, 09:43 am Last Edit: Dec 31, 2013, 10:16 am by OttoF Reason: 1
Hello chetto

if you want to use sql you have to install following things

Yun für php und sql

Installieren

opkg update
opkg install .....
php5
php5-cgi
php5-cli
php5-mod-sockets, // for php bridge
php5-mod-json        // for php bridge
php5-mod-sqlite3
php5-mod-session
zoneinfo-core
zoneinfo-europe

nano ( editor  )

edit In File
etc\config\uhttpd
list interpreter    ".php=/usr/bin/php-cgi"
/etc/init.d/uhttpd restart

For communication  php on yun side and 32u

Download bridge library for yun Php


https://github.com/arduino/YunBridge/tree/master/bridge/php
------------------------------------------------

Code: [Select]

<?php

include_once ("bridgeclient.class.php");

$client = new bridgeclient();

if (
$client->get("modus") == "a")
{
      
$db=new SQLite3("/www/sd/Aqarium/Aquarium.db");

      
$SQL "select * from sollwertelicht order by Schaltzeit_ts";
      
$resultSollwerteLicht $db->query($SQL);
...............

 
$client->put("command",$Senden);


OttoF

values from and to 32u

Code: [Select]

// Istwertausgabe means actuall values on arduino

  istwerte = "";
  for(int i = 1; i <=9; i++)
  {
     istwerte = istwerte + String(map(Regelwert[i],0,254,0,100))+ "#";
  }


  if (last_istwerte != istwerte)
  {
    last_istwerte = istwerte;
    Bridge.put("istwerte",istwerte);
    delay(50);
}



php yun side
Code: [Select]

<?php
include ("bridgeclient.class.php");
$client = new bridgeclient();


$IstwerteBridge $client->get("istwerte");
$Istwert explode("#"$IstwerteBridge);

for (
$i 0$i <= 8$i++) {
        if (
$Istwert[$i] > 100)
        goto 
Ende;
}




chetto983

i do some test:

No installation of mysql on arduino but only a php page recall:

Arduino code:
Code: [Select]

// temp to SQL

#include <Bridge.h>
#include <HttpClient.h>
#include <Process.h>
Process date;
float temperatura = 0.00 ;
int umidita = 0;




void setup() {
 
  
 
  
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);
  if (!date.running())  {
      date.begin("date");
      date.addParameter("+%T");
      date.run();
    }
     Serial.begin(9600);

  while (!Serial); // wait for a serial connection

    delay (1000);
  
   digitalWrite(13, LOW);

 
}

void loop() {
   digitalWrite(13, LOW);
  
  temperatura = ((A0 * 0.0032) - 0.5) / 0.01;
  int dummy1 = (int) temperatura;
  String temp =  String((dummy1), DEC);
  int randNumber = random(99);
 
 
  // Initialize the client library
  HttpClient client;



 

 //********************

 // metto a posto la data e l'ora
String ora = getora(); //ora
 String dummy = getdata();
 String anno = dummy.substring(6, 8); //
 String data = dummy.substring(0,5); // data
 anno = "20" + anno + "-"; // metto a posto l'anno
 data.replace("/","-");
 data = anno + data;
 
 data += "%20" + ora;
 data.trim();
 //**********1*************
 

 
 client.get("http://www.ilchetto.it/inserisci.php?tempo="+ data +"&temperatura="+ temp + "&umidita="+ randNumber);
 //client.get("http://www.ilchetto.it/inserisci.php?temperatura="+ temp + "&umidita="+ randNumber);
String risp;
 while (client.available()) {
    char c = client.read();
    risp += c;
    }
    risp.trim();
    
if (risp == "dati inseriti"){
 digitalWrite(13, HIGH);
}
Serial.println(risp);
risp = "";
// digitalWrite(13, HIGH);
  delay(10000);
}

String getora(){
  Process date;
  date.begin("date");
  date.addParameter("+%T");
  date.run();
  if (date.available()) {
    String timeString = date.readString();   
    return timeString;
  }
 date.close();
}
String getdata(){
  Process date;
  date.begin("date");
  date.addParameter("+%D");
  date.run();
  if (date.available()) {
    String timeString = date.readString();   
    return timeString;
  }
 date.close();
}



php code:

Code: [Select]

<?php


include(
"configurazione.php");



if(@$_REQUEST['temperatura']!="")
{

        
$tempo=mysql_real_escape_string($_REQUEST['tempo']);
$temperatura=mysql_real_escape_string($_REQUEST['temperatura']);
$umidita=mysql_real_escape_string($_REQUEST['umidita']);


mysql_query("INSERT INTO `temperatura`(`ID`, `time`, `temperatura`, `umidita`) VALUES (\"\",'$tempo', $temperatura,$umidita);");

echo "dati inseriti";

}
else
{
echo "errore";

die();
}

?>






Go Up