Connect SenseCAP API in Laravel
PRELIMINARY
This discusses how the API in SenseCAP can communicate with applications created by yourself. In this case SenseCAP will communicate with Laravel to handle API to API. The scope for this tutorial is only to retrieve GPS values (longitude and latitude), but in essence all data can be retrieved read the sensecap documentation. Before working, there are things that need to be installed and paid attention to.
# REQUIREMENTS
Web Service (Apache/NGINX)
Composer (For install Laravel)
POSTMAN (For Testing API)
# INFORMATION
PHP 8.1
Laravel 10
DISCUSSION
In this case, install the requirements first, then install Laravel.
composer create-project laravel/laravel location-sensecap-app
After that, configure the link from SenseCAP by filling in the .env file in the root folder and adding it to the bottom of the file.
API_URL_SENSECAP=https://sensecap.seeed.cc/openapi
API_KEY_SENSECAP=YOUR_API_ID_SENSECAP
API_PASS_SENSECAP=YOUR_ACCESS_API_KEYS_SENSECAP
API_API_ID_SENSECAP and API_ACCESS_API_KEYS_SENSECAP can be seen in the SenseCAP Menu in Security > Access API keys. Click the Create Access Key button.
Next, click on the contents of the API ID column to get the API ID and Access API keys.
Add a file in the config folder, then name it custom.php. Fill in the following configuration so that it can become a global variable in the .env file.
Create a MainTrait.php file in app/Traits, write it in the following code. And this file is a global handling response.
Then create a controller file in app/Http/Controllers/Api/Transaction with the file name LocationController.php. For handling from route to service.
Create a LocationService.php file for handling return responses in the repository. Create the file in app/Services/Transaction.
Before going to the next step, it is very important that the data you want to take from SenseCAP in this tutorial is only GPS data (longitude and latitude).
SenseCAP has provided API documentation, in this tutorial we will use the Get the latest data of the device API.
Create a LocationRepository.php file for API access to SenseCAP. Create the file in app/Repositories/Transaction.
And finally add the route in the api.php file in the routes folder.
Selanjutnya jalankan di cmd atau terminal :
php artisan optimize
php artisan serve
After Laravel is running, the data can be viewed using the POSTMAN application, as follows.
Akhirnya, Cara Connect API SenseCAP in Laravel telah selesai. Terimakasih sudah mengikuti tutorial ini. Tunggu tutorial berikutnya ya.
Download Source Code : https://github.com/budiodank/location-sensecap-app
Link PDF : https://drive.google.com/file/d/1K9Chh6oc5y4DZZKeIBUClYhdocT8xoQy/view?usp=sharing