Here is what my JSON receives from TTN cloud up to webhook.site.
With all my code below, I receive success => true, message => ‘Data received successfully’, but I receive null in data.
Why? Do you have any advice to give me ?
JSON :
{
“uplink_message”: {
“decoded_payload”: {
“humidity”: 52.49,
“pressure”: 1015.64,
“temperature1”: 22.87,
“temperature2”: 22.71
}
}
}
Controllers :
class InsertData extends ResourceController
{
protected $modelName = ‘App\Models\MinsererDonnees’;
protected $format = ‘json’;
// Function to retrieve the data
public function index()
{
// Retrieves the JSON data sent by the request
$queryData = file_get_contents('php://input');
// Checks whether data has been received
if ($queryData !== false) {
// Responds to the request with a success message and the data received
return $this->response->setJSON([
'success' => true,
'message' => 'Data received successfully',
'data' => json_decode($queryData, true)
])->setStatusCode(200);
} else {
// Responds to the request with an error message if no data has been received
return $this->response->setJSON([
'success' => false,
'message' => 'Error retrieving request data'
])->setStatusCode(400);
}
}
}