void loop () {
Serial.println("Request Weather....");
Particle.publish("get_min
[quote="ScruffR, post:7, topic:58650"]
what do you see as in the webhook log ([console.particle.io/integrations ](http://console.particle.io/integrations))?
[/quote]
_weather");
delay(60000);
}
void setup () {
Particle.subscribe("hook-response/get_min_weather", handleForecastReceived, MY_DEVICES);
getData();
}
// Gets called when weather data is ready
void weatherForecast(const char *event, const char *data) {
String str = String(data);
String locationStr = tryExtractingString(str, "<location>", "</location>");
String weatherStr = tryExtractingString(str, "<weather>", "</weather>");
String tempratureStr = tryExtractingString(str, "<temprature_c>", "</temprature_c>");
String windStr = tryExtractingString(str, "<wind_string>", "</wind_string>");
if(locationStr != NULL) {
tft.print("At Location: " + locationStr);
}
if(weatherStr != NULL) {
tft.print("The weather is: " + weatherStr);
}
if(tempratureStr != NULL) {
tft.print("The temprature is: " + tempratureStr + String(" *C"));
}
if(windStr != NULL) {
tft.print("The wind is: " + windStr);
}
}
// Text that is found between start and end will be returned in str
// Ex: startbarend -> bar
String tryExtractingString(String str, const char* start, const char* end) {
if (str == NULL) {
return NULL;
}
int idx = str.indexOf(start);
if (idx < 0) {
return NULL;
}
int endIdx = str.indexOf(end);
if (endIdx < 0) {
return NULL;
}
return str.substring(idx + strlen(start), endIdx);
}
void getData()
{
// Publish an event to trigger the webhook
// Som random 40.4406,-79.9959
Particle.publish("forecast", "40.4406,-79.9959", PRIVATE);
}
Event:
get_min_weather
ID:
............... <--- I am just hiding it, but its in there
Target:
darksky.net
Created:
December 3rd, 2020
TEST
EDIT
DELETE
INTEGRATION INFO
Event Name
The Particle event name that triggers the webhook
get_min_weather
Full URL
The target endpoint that is hit when the webhook is triggered
https://darksky.net/forecast/59.9116,10.7334/si12/en
Request Type
The standard web request method used when the webhook is triggered
GET
Request Format
How the webhook data will be encoded and passed to the target endpoint
Query Parameters
Query Parameters
Parameters to append the URL string when hitting the webhook endpoint
{
"event": "{{{PARTICLE_EVENT_NAME}}}",
"data": "{{{PARTICLE_EVENT_VALUE}}}",
"coreid": "{{{PARTICLE_DEVICE_ID}}}",
"published_at": "{{{PARTICLE_PUBLISHED_AT}}}"
}
Enforce SSL
Whether your webhook will will validate the certificate against its certificate authority chain
Yes
EXAMPLE DEVICE FIRMWARE
Trigger Integration
Put this code in your firmware to trigger this integration Docs
void loop() {
// Get some data
String data = String(10);
// Trigger the integration
Particle.publish("get_min_weather", data, PRIVATE);
// Wait 60 seconds
delay(60000);
}
Get Integration Response
Put this code in your firmware to get a response from this integration Docs
void setup() {
// Subscribe to the integration response event
Particle.subscribe("hook-response/get_min_weather", myHandler, MY_DEVICES);
}
void myHandler(const char *event, const char *data) {
// Handle the integration response
}