i want to store data from a temperature sensor connected in A0 pin.
In linino side with mysql-server, i created a sql database called 'ARDUINO' which contains a table, called 'temperatura' with 3 columns: 'id', 'data' and 'tempdegree'.
How can Arduino fill this table with the sensor Data Output?
mysql> CREATE DATABASE ARDUINO;
mysql> USE ARDUINO;
mysql> CREATE TABLE temperatura (id INT, data VARCHAR(20), tempdegree VARCHAR(20));
mysql> SHOW TABLES;
When i try to run it, in the linino console, with the command: /usr/bin/python /mnt/sda1/mysql.py , it returns me an error :" Error 2002: Can't connect to local MySQL server through socket '/tmp' (146)
Traceback (most recent call last):
File "/mnt/sda1/mysql.py", line 25, in
if con:
NameError: name 'con' is not defined
Can you help me please?
My bind adress, in the mysql server is defined by arduino IP in my lan, in this case 192.168.0.104.
I have to do that, to link the toad software installed on my PC, to the database installed on linino side.
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
+ guidata 1.6.1, guiqwt 2.3.1
Type "scientific" for more details.
>>> runfile('C:/Users/Nuno/.spyder2/mysql.py', wdir=r'C:/Users/Nuno/.spyder2')
('INSERT INTO NossoTeste (valor,tensao) VALUES(%s,%s)', (5, 4.88))
>>>
#include <Process.h>
void setup() {
// put your setup code here, to run once:
Bridge.begin();
}
void loop() {
// put your main code here, to run repeatedly:
}
void insertdb() {
Process p;
p.begin("/usr/bin/python /mnt/sda1/mysql.py");
p.addParameter("1");
p.addParameter("64");
p.run();
}
But it didn’t work, values 1 and 64 weren’t inserted in my db.
#include <Process.h>
void setup() {
// put your setup code here, to run once:
Bridge.begin();
insertdb();
}
void loop() {
// put your main code here, to run repeatedly:
}
void insertdb() {
Process p;
p.begin("/usr/bin/python");
p.addParameter("/mnt/sda1/mysql.py");
p.addParameter("10");
p.addParameter("2.27");
p.run();
}
if i put values in addparameter, this work perfectly.
Ex:
#include <Process.h>
void setup() {
// put your setup code here, to run once:
Bridge.begin();
insertdb();
}
void loop() {
// put your main code here, to run repeatedly:
}
void insertdb() {
Process p;
p.begin("/usr/bin/python");
p.addParameter("/mnt/sda1/mysql.py");
p.addParameter("10");
p.addParameter("2.27");
p.run();
}
But if i put values from a variable, it returns an error.
Ex:
#include <Process.h>
int sensorPin = 0;
int teste1 = 1005;
int teste2= 4.23;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Bit \t Tensao (V)");
Bridge.begin();
insertdb(teste1, teste2);
}
void loop() {
// put your main code here, to run repeatedly:
int reading = analogRead(sensorPin);
float tensao = reading * 4.88;
tensao /= 1024.0;
Serial.print(reading);
Serial.print("\t");
Serial.print("\t");
Serial.print(tensao);
Serial.print("\t");
Serial.print("\n");
delay(1000);
}
void insertdb(int x, int y) {
Process p;
p.begin("/usr/bin/python");
p.addParameter("/mnt/sda1/mysql.py");
p.addParameter(x);
p.addParameter(y);
p.run();
}
the error is:
Arduino: 1.5.6-r2 (Windows 8), Placa:"Arduino Yún"
ler_tensoes.ino: In function 'void insertdb(int, int)':
ler_tensoes:32: error: conversion from 'int' to 'const String' is ambiguous
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61: note: candidates are: String::String(const __FlashStringHelper*)
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59: note: String::String(const char*)
ler_tensoes:33: error: conversion from 'int' to 'const String' is ambiguous
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61: note: candidates are: String::String(const __FlashStringHelper*)
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59: note: String::String(const char*)
String stringOne = String(analogRead(0), DEC); // using an int and a base
String stringOne = String(13); // using a constant integer
...
void insertdb(String x, String y) {
...