我有一个变量集$ TSID2,但是当它被调用时,它什么都不返回。我已尝试使用它全球化它仍然无法正常工作。我已经在其中包含了脚本的相关部分(问题行是最后一行)。我已经尝试将它改成几个不同的名字,尝试直接回声等等,似乎没有任何东西可以使用它。 出了什么问题?
// --------------------------
// INSERT YOUR SENSOR IDS HERE - THIS IS FOR BOTH CHANNEL A AND B. See thread for info.
$sensorida = 'xxxx';
$sensoridb = 'xxxx';
// INSERT YOUR THINGSPEAK API KEYS HERE FOR PM10 RESULTS. See thread for info, but can be found in your sensor's JSON file.
// TSID and TSKey are for Channel A and TSI2 and TSKey2 are for Channel B.
$TSID = 'xxxx';
$TSKey = 'xxxx';
$TSID2 = 'xxxx';
$TSKey2 = 'xxxxx';
// --------------------------
// USE COLOR BLENDING (SHADING) LIKE PURPLEAIR DOES AS VALUE GETS NEARER TO NEXT LEVEL (1) OR JUST USE STATIC COLOR TO COLOR (0)
$useblending = 1;
// --------------------------
// SHOW TIMESTAMP OF SENSOR DATA - 1= YES 0=NO
$showtimestamp = 1;
// TIMEZONE MUST BE IN FORMAT PHP RECOGNIZES - SEE PHP MANUALS IF YOU NEED HELP
$timezone = 'America/Los_Angeles';
// AVERAGE THE AQI VALUES BETWEEN CHANNEL A AND B IN ADDITION TO THE PM VALUES (1), OR SHOW BOTH SENSORS INDIVIDUALLY (0)
$averageaqi = 1;
// SHOW UG/M3 RESULTS TO 2 DECIMAL PLACES INSTEAD OF JUST 0 IF LESS THAN 1
$showdecimal = 1;
// INSERT YOUR LOCATION OR SENSOR NAME
$sensorname = "My Sensor";
// DISPLAY PM10 PARTICLE VALUES
// Note: You can display the PM10 AQI value by using the variable $AQI10. Put it in some HTML.
$showpm10 = 0;
// --------------------------
// SQL LOGGING MODE
// 0 = DON'T LOG ANY RESULTS; JUST DISPLAYS THE PURPLEAIR RESULTS AS NORMAL
// 1 = LOG THE RESULTS TO DATABASE AND DISPLAY THE PURPLEAIR RESULTS AS NORMAL
// 2 = LOG THE RESULTS TO DATABASE AND DON'T DISPLAY ANYTHING (CRON-TYPE SCRIPT)
//
// Note: The AQI logged results are always combined values (A+B) like what is shown on Purpleairs site. You can change the script if you want it done differently.
// PM values are logged as each channel.
//
// IMPORTANT: YOU MUST CREATE THE DATABASE AND ITS LAYOUT - A MYSQL EXPORT IS AVAILABLE IN THE THREAD.
$logtosql = 0;
// --------------------------
//MYSQL PARAMETERS FOR SQL LOGGING MODES
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$tbldata = "purpleairdata";
if ($sensorida == "")
{
echo "No sensor ID A entered in Script source!";
die;
}
if ($sensoridb == "")
{
echo "No sensor ID B entered in Script source!";
die;
}
if ($TSID == "" || $TSID2 = "")
{
echo "No Thingspeak credentials entered.";
die;
}
//Make sure Purpleair's Site can be reached
$host = 'purpleair.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 10)) {
fclose($socket); //Wer'e good
} else {
echo 'The PurpleAir service is currently unreachable. Try again later.';
error_log("Could not connect to the PurpleAir servers for the script data.");
die;
}
//Make sure Thingspeak's Site can be reached
$host = 'api.thingspeak.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 10)) {
fclose($socket); //Wer'e good
} else {
echo 'The Thingspeak service is currently unreachable. Try again later.';
error_log("Could not connect to the Thingspeak servers for the script data.");
die;
}
//Get the sensor data via JSON
$pajsona = file_get_contents("http://www.purpleair.com/json?show=" . $sensorida);
$pajsonb = file_get_contents("http://www.purpleair.com/json?show=" . $sensoridb);
//Get the PM10 value from Thingspeak
$pm10 = file_get_contents("https://api.thingspeak.com/channels/" . $TSID . "/fields/field3/last.txt?api_key=" . $TSKey);
$pm102 = file_get_contents("https://api.thingspeak.com/channels/" . $TSID2 . "/fields/field3/last.txt?api_key=" . $TSKey2);
答案 0 :(得分:0)
在if语句中被覆盖,错过了额外的=。