In this blogpost we will try to access the data from a Crodeon weather station from the cloud using the Crodeon Rest API. The cloud technology that we will explore in this example is AWS Lambda and Go.
About AWS Lambda and the Crodeon weather station
AWS Lambda is a serverless, event-driven compute service on which you can run code for almost any type of application or backend service without the need to provision or manage servers. Visit this page for more info about AWS Lambda.
The Crodeon weather station is becoming a popular weather measurement tool, mainly because of its easy deployment, mobile usability and affordable price. The weather station offers a real-time connection to the cloud and out-of-the-box API functionality to integrate the data in your own software. Besides wind, rain, temperature and humidity you can also add more exotic sensors to measure CO2, air quality, water level, pressure, etc… Visit this page for more info about the Crodeon weather station.
Create your AWS Lambda function and trigger
First of all we create a new function called weather-data. For this example we will use Go as our programming language.
Next we have to add a trigger. This is how we let AWS invoke the function.
For this example we will choose an API Gateway, but AWS offers some interesting alternatives like a Shopify purchase event or an Amazon Alexa trigger.
Now we can see this API gateway will act as a trigger for our newly created lambda function.
Writing the Lambda code to call weather data
The web code editor of AWS doesn’t support Go, so we will write our code in Visual Studio Code and upload it as a .zip file.
The zipped file and the contents must have the name of the handler, in this case “main”.
Now it’s time to test our code. Click the Test tab and create a new test event. In this example we will choose the API-gateway-AWS-proxy template.
Enter the Reporter ID as the path and the x-api-key and authentication credentials in the headers of the event document template that AWS presents us. Contact Crodeon at firstname.lastname@example.org to get your free demo API credentials.
The test is successful and the body data contains the values we needed. For this demo we only called 4 of the weather parameters as well as the date and time in UTC format.
Start your own sensor project
That’s it! We hope this was useful for some of you. Don’t hesitate to contact us for any further questions about the Crodeon weather station or the Crodeon API. Visit our website to read more about the Reporter, the world’s easiest sensor device for real-time remote monitoring.
Click here to download the Golang source code and the build file that we used for this demo.