【发布时间】:2015-10-03 03:43:16
【问题描述】:
所以,我有这样的 arduino 代码:
#include <Ethernet.h>
#include <SPI.h> m
#include "kSeries.h"
kSeries K_30(8,9);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 229 };
byte gateway[] = { 192, 168, 1, 1 };
byte server[] = { 192, 168, 1, 138 }; // alamat host Server
String location = "GET http://192.168.1.138/SIMON/datasetiapdetik.php?";
//String location = "POST /alvin/datasetiapdetik.php?";
String host = "Host: 192.168.1.138";
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("connecting...");
}
void loop()
{
double co2 = K_30.getCO2('p');
// Print the value on Serial
Serial.print(co2);
Serial.println("ppm \t");
String data;
data+="";
data+="device=arduino";
data+="&A0=";data+=co2;
data+="&submit=Submit";
Serial.print(data);
while (client.connect(server, 80)) {
Serial.println("Sending data..");
//lokasi halaman atau form
client.print(location);
client.print(data);
client.println("HTTP/1.1");
client.println(host);
//client.println("Connection: close");
//char web=client.read();
Serial.print(location);
Serial.print(data);
client.stop();
}
/*
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(50);
}*/
delay(2000);
}
和这样的 php 代码:
<?php
include "config/koneksi.php";
error_reporting(0);
date_default_timezone_set('Asia/Jakarta');
// EDIT: Your mysql database account information
$tablename = "input";
$localhost = "localhost";
$date = date('y-m-d');
$waktu = date('H:i');
$tanggal = date('y-m-d');
$menit = date('i');
//Create tabel everyday
$sql = "\n"
. " CREATE TABLE IF NOT EXISTS `input` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT ,\n"
. " `date` date NOT NULL ,\n"
. " `time` time NOT NULL,\n"
. " `device` text NOT NULL ,\n"
. " `A0` int( 11 ) NOT NULL ,\n"
. " PRIMARY KEY ( `ID` ) ) ENGINE = InnoDB DEFAULT CHARSET = latin1;";
$create = mysql_query($sql);
$sql = "SELECT *
FROM `$tablename`
WHERE `date`='$date' and `time`='$waktu'
";
$uji = mysql_num_rows(mysql_query($sql));
if ($menit % 1 == 0 and $uji < 1) {
$query1 = "INSERT INTO `input` (date,time,device,A0 VALUES ('$date','$waktu','$_GET[device]','$_GET[A0]')";
$result = mysql_query($query1);
}
else {
}
echo 'GET = ' . htmlspecialchars($_GET["device"]) . '!<br>';
echo 'GET = ' . htmlspecialchars($_GET["A0"]) . '!<br>';
echo "<h1>Sistem Monitoring Siap!!</h1>";
echo `\n`;
?>
它每分钟读取一次数据,而且很好。但是当我将 $menit % 1 更改为 % 5 时,它不起作用。如何更改间隔以便每 5 分钟读取一次数据?谢谢
【问题讨论】:
-
这个运行是怎么回事,也许它超时了 - 你考虑过 cronjob 吗?
-
我是新手。我如何从上面更改代码?或者你可以给我一个新的?