Hello, i´m new whit the photon an i’ve been triyin to send this dates form particle.io to my own mysql but these dates not reach in the database an i don´t know which is the problem
This is the code php:
<?php
include_once('conexion.php');
$link = mysql_connect(IConnectInfo::HOST, IConnectInfo::UNAME, IConnectInfo::PW)
or die('Could not connect: ' . mysql_error());
mysql_select_db(IConnectInfo::DBNAME) or die('Could not select database');
if(isset($_GET['watts']) ) {
$poswatts = $_GET['watts'];
if($poswatts<0 ) $poswatts = 0;
date_default_timezone_set("UTC");
$currutctime = date("Y-m-d H:i:s", time());
$sql = 'INSERT INTO datos '.
'(watts,unixtime) '.
'VALUES ( '. $poswatts .', "'. $currutctime .'");';
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
echo("success-" .mysql_insert_id());
mysql_close($link);
}
?>
This is the code photon:
// This #include statement was automatically added by the Particle IDE.
#include "lib1.h"
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"
#include "application.h"
#include <string.h>
#include <math.h>
HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {
{ "Content-Type", "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers with NULL
};
TCPClient client;
const int voltage = 220;
double average = 0.0;
double sum = 0.0;
int count = 0;
static unsigned long secondInterval = 1000;
static unsigned long minuteInterval = 57000;
static unsigned long prevMinute = 0;
static unsigned long prevSecond = 0;
unsigned long now;
void setup()
{
Serial.begin(9600);
Serial.println("hola mundo");
}
void loop()
{
double watts = 70.3 ;
sendWatts(watts);
delay(3000);
}
void sendWatts(double wattreading){
String val = "watts=70.5";
request.hostname = "localhost";
request.port = 80;
request.path = "\getvariables.php";
request.body = val;
String cadena = request.hostname+"-"+request.port+"-"+request.path+"-"+request.body;
http.get(request, response, headers);
debug(cadena ,"1");
}
String doubleToString(double input,int decimalPlaces){
if(decimalPlaces!=0){
String string = String((int)(input*pow(10,decimalPlaces)));
if(abs(input)<1){
if(input>0)
string = "0"+string;
else if(input<0)
string = string.substring(0,1)+"0"+string.substring(1);
}
return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
}
else {
return String((int)input);
}
}
void debug(String message, String value) {
Spark.publish("DEBUG", message);
}