This project shows you how you can send environmental data as event logs to Meadow.Cloud using a Project Lab.
Project Lab is the most functional IoT prototyping platform on the planet. No more breadboards, complicated wiring, or soldering. Project Lab was built from the ground up using the industry's most powerful, capable, and reliable sensors, components, and connectors.
Meadow.Foundation a platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, It's completely open source and maintained by the Wilderness Labs community.
Before you dive in this project, ensure that your Meadow board and development environment is fully up to date. Check the Release Notes section to double check.
Step 1 - Provision your Project Lab to Meadow.CloudSince we're sending telemetry data to Meadow Cloud, you'll need to create an account and provision your Project Lab.
Step 2 - Create a Meadow Application projectCreate a new Meadow Application project in Visual Studio 2022 for Windows or macOS and name it Meadow.Cloud_Logging.
Step 3 - Add the required NuGet packagesFor this project, search and install the following NuGet packages:
Step 4 - Add Image AssetsAdd a Resources
folder and add the following image assets.
Select all these images and set the Build Action to Embedded Resource.
Step 5 - Setup Configuration FilesUpdate the meadow.config.yaml
file below:
Device:
# Name of the device on the network.
Name: MeadowF7V2_ConfigSample
# Uncomment if SD card hardware present on this hardware (e.g., Core-Compute module with SD add-on)? Optional; default value is `false`.
# SdStorageSupported: true
# Control how the ESP coprocessor will start and operate.
Coprocessor:
# Should the ESP32 automatically attempt to connect to an access point at startup?
# If set to true, wifi.config.yaml credentials must be stored in the device.
AutomaticallyStartNetwork: true
# Should the ESP32 automatically reconnect to the configured access point?
AutomaticallyReconnect: true
# Maximum number of retry attempts for connections etc. before an error code is returned.
MaximumRetryCount: 7
# Network configuration.
Network:
Interfaces:
- Name: WiFi
UseDHCP: true
IPAddress:
NetMask:
Gateway:
# Which interface should be used?
DefaultInterface: WiFi
# Automatically attempt to get the time at startup?
GetNetworkTimeAtStartup: true
# Time synchronization period in seconds.
NtpRefreshPeriodSeconds: 600
# Name of the NTP servers.
NtpServers:
- 0.pool.ntp.org
- 1.pool.ntp.org
- 2.pool.ntp.org
- 3.pool.ntp.org
# IP addresses of the DNS servers.
DnsServers:
- 1.1.1.1
- 8.8.8.8
These
settings enable the Project Lab to connect to WiFi when powered on and when connected, automatically get date and time from an NTP server.
Update wifi.config.yaml
uncommenting the WiFi fields and enter your SSID and password credentials:
Credentials:
Ssid: Ssid
Password: Password
Its recommended to set the Log level to Trace in the app.config.yaml
file to keep an eye on the console output for when the board is logging in to Meadow.Cloud and sending event logs successfully.
# Adjust the level of logging detail.
Logging:
LogLevel:
Default: Trace
Step 6 - Write the code for Meadow.Cloud_LoggingThis project has the following structure:
Lets briefly go over every file:
- IMeadowCloudLoggingHardware - The intention of this interface is to define what components we're using for this project, which in this case is a display, an BME68x environmental sensor and an RGB LED, which they're all onboard on a Project Lab.
- MeadowCloudLoggingHardware - This is a particular definition of
IMeadowCloudLoggingHardware
where we declare and create a Project Lab instance, and initialize every component defined. - DisplayController - The sole purpose of this class is to do all the drawing of the HMI screen on the display. We use MicroLayouts, so you can see how we can use Label to show text, Picture to draw images like the sync and WiFi icons, Box to draw colored rectangles for backgrounds, etc. You can read more on MicroLayouts on our docs.
- MainController - This class is the main business logic that has access to a hardware object and all sub-controllers (like the DisplayController in this case). In the
Initialize
method, notice the logic to register a Cloud Logger service, which is then used in theEnvironmentalSensorUpdated
event handler whenever the environemental sensor does a read, it usescloudLogger.LogEvent()
method to sendtemperature
,pressure
andhumidity
values to Meadow.Cloud - MeadowApp - In the app's main class, we create a hardware object (
MeadowCloudLoggingHardware
in this case), we also take the WiFi network adapters and both are passed to the MainController when creating an object, and finally call theInitialize
andRun
methods respectively.
Click the Run button in Visual Studio and keep an eye on the console output, you will see the app trying to log in to Meadow.Cloud and eventually start sending event logs to the servers.
In the Project Lab screen, you will see Sending data..
and Data sent!
strings on the status label along with the Sync icon active when it happens, like below:
Additionally, if you go to Meadow.Cloud, on the Device section, look for your device and go to the logs section and choose events in the Drop down menu, you will see event logs sent from your Project Lab:
This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Meadow.Foundation.
- It comes with a huge peripheral driver library with drivers for the most common sensors and peripherals.
- The peripheral drivers encapsulate the core logic and expose a simple, clean, modern API.
- This project is backed by a growing community that is constantly working on building cool connected things and are always excited to help new-comers and discuss new projects.
Comments
Please log in or sign up to comment.