i Have an issue to write from a log file to a data base
look i have a C program Read values from DHT11 sensor
Code: Select all
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define MAX_TIME 85
#define DHT11PIN 7
#define ATTEMPTS 5
int dht11_val[5]={0,0,0,0,0};
int dht11_read_val()
{
uint8_t lststate=HIGH;
uint8_t counter=0;
uint8_t j=0,i;
for(i=0;i<5;i++)
dht11_val[i]=0;
pinMode(DHT11PIN,OUTPUT);
digitalWrite(DHT11PIN,LOW);
delay(18);
digitalWrite(DHT11PIN,HIGH);
delayMicroseconds(40);
pinMode(DHT11PIN,INPUT);
for(i=0;i<MAX_TIME;i++)
{
counter=0;
while(digitalRead(DHT11PIN)==lststate){
counter++;
delayMicroseconds(1);
if(counter==255)
break;
}
lststate=digitalRead(DHT11PIN);
if(counter==255)
break;
// top 3 transistions are ignored
if((i>=4)&&(i%2==0)){
dht11_val[j/8]<<=1;
if(counter>16)
dht11_val[j/8]|=1;
j++;
}
}
// verify checksum and print the verified data
if((j>=40)&&(dht11_val[4]==((dht11_val[0]+dht11_val[1]+dht11_val[2]+dht11_val[3])& 0xFF)))
{
printf("%d.%d\n",dht11_val[0],dht11_val[1]);
return 1;
}
else
return 0;
}
int main(void)
{
int attempts=ATTEMPTS;
if(wiringPiSetup()==-1)
exit(1);
while(attempts)
{
int success = dht11_read_val();
if (success) {
break;
}
attempts--;
delay(500);
}
return 0;
}
Code: Select all
* * * * * echo `/home/pi/wiringPi/dht11` >> /home/pi/temp.log
Code: Select all
36.0
36.0
36.0
i try to do it but i have some problem
my PHP code
Code: Select all
<?php
mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
mysql_select_db('database') or die(mysql_error());
$lines = file('temp.log');
$humidity = "";
foreach($lines as $line => $hum) {
$humidity .= "'$hum',";
}
mysql_query("INSERT_INTO `humidite` VALUES (NULL , $humidity 'test_record')") or die(mysql_error());
?>
if any one have a python solution thanks
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT_INTO `humidite` VALUES (NULL , '36.0 ','36.0 ','36.0 ','36.0 ','36.0 ','3' at line 1