Hey, I created webhook to send temperature data, in event panel it shows that hook has been sent, but my website doesn’t receive anything.
And there’s also weird response from Webhook in internal-terminal even if its not called!
Here’s my particle Code
#include "IRremoteLearn.h"
#include "math.h"
const int SEND_PIN = TX;
int ky013Pin = D3; // Digital I/O pin connected to KY-013 OUT pin
float thermistorNominal = 10000; // Thermistor resistance at 25 degrees Celsius
float temperatureNominal = 25; // Temperature at which thermistor resistance is nominal
float bCoefficient = 3950; // Beta coefficient of thermistor
float seriesResistor = 10000; // Resistance of series resistor
float thermistorResistance, temperatureC, temperatureF;
// defaults to TX pin if no pin specified, see IRsend::IRsend(int txpin) header for PWM pins available
IRsend irsend(SEND_PIN);
void setup() {
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);
irsend.sendNEC(0x1FF02FD, 32);
delay(1000);
digitalWrite(D7, LOW);
delay(3000);
// particle.variable("wakeup", data)
Particle.function("wakeup", testData);
}
void loop() {
int reading = analogRead(ky013Pin); // Read analog input
float voltage = reading * (3.3 / 4095.0); // Convert reading to voltage87
thermistorResistance = seriesResistor * (3.3 / voltage - 1); // Calculate thermistor resistance
temperatureC = 1 / (log(thermistorResistance / thermistorNominal) / bCoefficient + 1 / (temperatureNominal + 273.15)) - 273.15; // Calculate temperature in degrees Celsius
temperatureF = temperatureC * 9.0 / 5.0 + 32.0; // Convert temperature to degrees Fahrenheit
Particle.publish("Temp:", String(temperatureC));
delay(10000);
makeJSON();
}
void makeJSON(){
char jsonStr[600] = "na";
char jsonTimeStr[12] = "na";
sprintf(jsonTimeStr, "%d:%.2d:%.2d", Time.hour(), Time.minute(), Time.second());
sprintf(jsonStr, "{\"updated\":%u, \"temperatureC\":%d}",
jsonTimeStr, temperatureC);
if(Particle.connected() && strlen(jsonStr) < 600) {
Particle.publish("hook-range", jsonStr);
}
}
// Receive data From Form post
int testData(String cmd) {
Particle.publish("Data", cmd);
if (cmd == "off") {
digitalWrite(D7, HIGH);
delay(3000);
digitalWrite(D7, LOW);
}
return 1;
}
Here’s my website code:
<?php
// Get the data from particle-argon.
if(empty($_POST['event'])) {
echo "No webhooks recieved. <br>";
} elseif($_POST['event'] == 'hook-range') {
$eventData = $_POST['data'];
$eventData = json_decode($eventData);
file_put_contents('alien-webhook.json', json_encode($eventData));
}
$jsonData = json_decode(file_get_contents('alien-webhook.json'), true);
var_dump($_POST);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>App - Test</title>
</head>
<body>
<h1>Testing IR Receiver</h1>
<form action="https://api.particle.io/v1/devices/XXXXXXXXXXXXXXXXXX/wakeup?access_token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" method="POST" target="hiddenFrame">
<button name="submit" value="off" id="submit" type="submit">Submit</button>
</form>
</body>
</html>