Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Capteur autonome Penn Avel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pronto 3
Capteur autonome Penn Avel
Commits
f0dd8800
Commit
f0dd8800
authored
3 weeks ago
by
BENTATA Hugo
Browse files
Options
Downloads
Patches
Plain Diff
Add TTN webhook for data retrieval and forwarding to Sensor Community
parent
e969cd47
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.DS_Store
+0
-0
0 additions, 0 deletions
.DS_Store
GW-V2/ttn_webhook.php
+50
-0
50 additions, 0 deletions
GW-V2/ttn_webhook.php
with
50 additions
and
0 deletions
.DS_Store
0 → 100644
+
0
−
0
View file @
f0dd8800
File added
This diff is collapsed.
Click to expand it.
GW-V2/ttn_webhook.php
0 → 100644
+
50
−
0
View file @
f0dd8800
<?php
// Récupération des données envoyées par TTN
$json
=
file_get_contents
(
'php://input'
);
$data
=
json_decode
(
$json
);
// Affichage des données reçues pour debug
echo
"Données reçues :
\n
"
;
print_r
(
$data
);
echo
"
\n
"
;
// Vérification de la structure des données reçues
if
(
!
isset
(
$data
)
||
!
isset
(
$data
->
analog_in_1
)
||
!
isset
(
$data
->
analog_in_2
))
{
echo
"Erreur : Données invalides. Vérifiez que les champs analog_in_1 et analog_in_2 sont présents."
;
return
;
}
// Création des données à envoyer vers Sensor Community
$post
=
new
stdClass
();
$post
->
sensordatavalues
=
[
(
object
)[
"value_type"
=>
"P1"
,
"value"
=>
$data
->
analog_in_1
],
(
object
)[
"value_type"
=>
"P2"
,
"value"
=>
$data
->
analog_in_2
]
];
// Initialisation de la requête cURL
$ch
=
curl_init
(
"http://api.sensor.community/v1/push-sensor-data/"
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
array
(
"X-Sensor: esp32-900881266"
,
// Valeur fixe
"X-PIN: 1"
,
"Content-Type: application/json"
,
"User-Agent: ttn-forwarder/1.0"
));
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
json_encode
(
$post
));
// Exécution de la requête et gestion des erreurs
$output
=
curl_exec
(
$ch
);
if
(
$output
===
false
)
{
echo
"Erreur cURL : "
.
curl_error
(
$ch
);
}
else
{
echo
"Réponse de Sensor Community : "
.
$output
;
}
curl_close
(
$ch
);
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment