-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.php
53 lines (34 loc) · 1.38 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require('./vendor/autoload.php');
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app['debug'] = true;
// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => 'php://stderr',
));
$app->get('/', function(){
return new Response('Nothing here', 405);
});
$app->post('/sigfox', function (Request $request) use ($app) {
$app['monolog']->addInfo('Downlink');
$app['monolog']->addInfo(sprintf('Content-Type %s', $request->headers->get('Content-Type')));
if ($request->headers->get('Content-Type') === 'application/json'){
$data = json_decode($request->getContent(), true);
$request->request->replace(is_array($data) ? $data : array());
}
$deviceId = $request->get('deviceId');
$app['monolog']->addInfo(sprintf('deviceId - %s', $request->get('deviceId')));
$app['monolog']->addInfo(sprintf('rssi - %s', $request->get('rssi')));
if (is_null($deviceId)){
return new Response("", 204);
}
$message = "01234567890ABCDE";
$output = array($deviceId=>array("downlinkData"=>$message));
$response = new Response(json_encode($output), 200);
$response->headers->set('Content-Type', 'application/json');
return $response;
});
$app->run();