Connect with us

IoT

Feeding my cat with AWS IoT GreengrassV2

Published

on

Setting up Greengrass Core

Navigate to the [AWS IoT Greengrass console in the us-west-2 region]
(https://us-west-2.console.aws.amazon.com/iot/home?region=us-west-2#/greengrassIntro) and straight away you might notice something a bit different.




AWS IoT Greengrass V2 console

AWS IoT Greengrass V2 console

Go ahead and select Set up one core device to begin the process of creating a single Greengrass Core.

Start by giving the core a name, for this project we’ll go with cat-feeder-01.




AWS IoT Greengrass V2 core device name

AWS IoT Greengrass V2 core device name

The next step is to define a group name for our cat feeders. We’ll go with cat-feeders. Greengrass groups allow us to perform continuous deployments to a select set of devices.




AWS IoT Greengrass V2 create thing group

AWS IoT Greengrass V2 create thing group

Preparing the IoT Device

In this step we’ll briefly go through setting up our Raspberry Pi for running Greengrass core. Start by logging into the device using SSH.

ssh pi@raspberrypi.local

Now we install the requirements needed to run AWS IoT Greengrass on the device.

sudo apt-get update
sudo apt-get install openjdk-8-jdk unzip curl python3-pip

# AWS CLI
pip3 install awscli --upgrade

AWS credentials

We will be executing the deployment of the device setup directly from the Raspberry Pi itself, which means that we need to have AWS credentials exposed. To do this, create an access key to use for the device temporarily during deployment

The keys should look something like the following




AWS IAM Access Keys

AWS IAM Access Keys

Export these keys by running the following on the Raspberry Pi, replacing the keys with your own.

export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Run Greengrass Core setup

We’re ready to deploy our new Greengrass core! Do this by following the instructions provided on the Greengrass core creation page. These commands can also be seen below.

# Download and extract the installer
curl -s https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-nucleus-latest.zip > greengrass-nucleus-latest.zip && unzip greengrass-nucleus-latest.zip -d GreengrassCore

# Run the installer
sudo -E java -Droot="/greengrass/v2" \
    -Dlog.store=FILE -jar ./GreengrassCore/lib/Greengrass.jar \
    --aws-region us-west-2 \
    --thing-name cat-feeder-01 \
    --thing-group-name cat-feeders \
    --component-default-user ggc_user:ggc_group \
    --provision true \
    --setup-system-service true \
    --deploy-dev-tools true

You will see a bunch of output indicating if things successfully register or not.




AWS IoT Greengrass V2 Deployment command output

AWS IoT Greengrass V2 Deployment command output

If everything went well you should see the output above. If that is the case you can now navigate back to the Greengrass AWS portal and open the Core devices page to view the state of your deployed devices.




AWS IoT Greengrass V2 core device list

AWS IoT Greengrass V2 core device list

Clicking on the new cat-feeder-01 device will present you with a nice healthy status and some more information about the core.




AWS IoT Greegnrass V2 cat-feeder-01 status

AWS IoT Greegnrass V2 cat-feeder-01 status

Running a Deployment

Depending on how you deployed your Greengrass core you may or may not have components already installed on your core. If you included --deploy-dev-tools true for example, you might see aws.greengrass.Cli installed as a component along with aws.greengrass.Nucleus.

Let’s go through an example of doing a deployment to install both of these dependencies in case they are not included on your Greengrass device. Start by navigating to the Deployments under Greengrass and select Create new deployment.




AWS IoT Greengrass V2 create a Deployment

AWS IoT Greengrass V2 create a Deployment

In the create new deployment screen give it a Name and select Thing group as the deployment target, followed by selecting cat-feeders. This will mean that all cat feeder devices will receive this deployment.




AWS IoT Greengrass V2 specify deployment details

AWS IoT Greengrass V2 specify deployment details

The next screen is the important one, we need to select the components that should be deployed to our core. Go ahead and select aws.greengrass.Cli and aws.greengrass.Nucleus for now, however, you can also browse any of the other public components.




AWS IoT Greengrass V2 specify deployment components

AWS IoT Greengrass V2 specify deployment components

Click next a couple more times and finalize the deployment by clicking Deploy at the end.

Navigate back to the details page under your cat-feeder-01 Greengrass core and you should see the two components we just deployed under its component list




AWS IoT Greengrass V2 view deployed components

AWS IoT Greengrass V2 view deployed components

Custom Cat Feeder component

With our Greengrass core deployed it’s time to create a brand new component and recipe for controlling my cat feeder.

Preparing to deploy a component

Deploying a component requires an S3 bucket to exist where the artifacts will live and be available to the Greengrass core device.

First, we will create a bucket that will house all our custom components in the future, along with generating an IAM policy that can be used by roles to access said artifacts

# Replace the AWS_ACCOUNT_ID with your account ID
# Replace the AWS_REGION with whatever region you are deploying into
aws s3 mb s3://greengrass-component-artifacts-${AWS_ACCOUNT_ID}-${AWS_REGION}

cat << 'EOF' > component-artifact-policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::greengrass-component-artifacts-${AWS_ACCOUNT_ID}-${AWS_REGION}/*"
            ]
        }
    ]
}
EOF

# Creates IAM policy that can be attached to roles
aws iam create-policy \
    --policy-name GreengrassV2ComponentArtifactPolicy \
    --policy-document file://component-artifact-policy.json

If you remember back to earlier on in this post when we deployed our Greengrass device, behind the scenes AWS Greengrass v2 deployed a role called GreengrassV2TokenExchangeRole that is attached to Greengrass and used to access AWS services.

We will now attach our brand new policy document to this role giving Greengrass core access to our components

aws iam attach-role-policy \
    --role-name GreengrassV2TokenExchangeRole \
    --policy-arn arn:aws:iam::277790246569:policy/GreengrassV2ComponentArtifactPolicy

Deploying a component version

Hurray! we’re ready to deploy our component. I’ve created a simple example for our cat feeder app available at t04glovern/aws-greengrassv2-cat-feeder, so for the purpose of this repo; clone it down locally.

#     "arn": "arn:aws:greengrass:${AWS_REGION}:${AWS_ACCOUNT_ID}:components:com.devopstar.FeedCat:versions:1.0.0",
#     "componentName": "com.devopstar.FeedCat",
#     "componentVersion": "1.0.0",
#     "creationTimestamp": 1608123861.393,
#     "status": {
#         "componentState": "REQUESTED",
#         "message": "NONE",
#         "errors": {}
#     }
# }
git clone https://github.com/t04glovern/aws-greengrassv2-cat-feeder

Within the project is an example of how you would lay out a project




AWS IoT Greengrass V2 component layout in repository

AWS IoT Greengrass V2 component layout in repository

Taking a look at the recipes/com.devopstar.FeedCat-1.0.0.yaml file you should find a simple example of how we can launch a python script that triggers the cat feeder on my desk

NOTE: you will need to change the AWS_ACCOUNT_ID & AWS_REGION variables if you plan to deploy this component also.

---
RecipeFormatVersion: '2020-01-25'
ComponentName: com.devopstar.FeedCat
ComponentVersion: 1.0.0
ComponentDescription: AWS IoT Greengrass component to feed your cat
ComponentPublisher: Nathan Glover
ComponentConfiguration:
  DefaultConfiguration:
    Message: meow
Manifests:
- Name: Linux
  Platform:
    os: linux
  Lifecycle:
    Run:
      Script: python3 {artifacts:path}/feed_cat.py '{configuration:/Message}'
      RequiresPrivilege: True
  Artifacts:
  - Uri: s3://greengrass-component-artifacts-${AWS_ACCOUNT_ID}-${AWS_REGION}/artifacts/com.devopstar.FeedCat/1.0.0/feed_cat.py

Deploying the component first needs us to upload the artifacts to S3 and this is done by running the following CLI command (ensuring to replace your own AWS_ACCOUNT_ID & AWS_REGION)

aws s3 cp \
    artifacts/com.devopstar.FeedCat/1.0.0/feed_cat.py \
    s3://greengrass-component-artifacts-${AWS_ACCOUNT_ID}-${AWS_REGION}/artifacts/com.devopstar.FeedCat/1.0.0/feed_cat.py

Then with the artifacts in S3 run the following to create a component version from inline recipe file

aws greengrassv2 create-component-version \
    --inline-recipe file://recipes/com.devopstar.FeedCat-1.0.0.yaml
# {
#     "arn": "arn:aws:greengrass:${AWS_REGION}:${AWS_ACCOUNT_ID}:components:com.devopstar.FeedCat:versions:1.0.0",
#     "componentName": "com.devopstar.FeedCat",
#     "componentVersion": "1.0.0",
#     "creationTimestamp": 1608123861.393,
#     "status": {
#         "componentState": "REQUESTED",
#         "message": "NONE",
#         "errors": {}
#     }
# }

Deploying & Running a component

The final step is to run a deployment that tells AWS IoT Greengrass core to run our new component com.devopstar.FeedCat. To do this navigate to the console and under the existing deployment, select Revise.




AWS IoT Greengrass V2 revise deployment

AWS IoT Greengrass V2 revise deployment

Navigate through until you are prompted to select the components to be deployed. This time select com.devopstar.FeedCat and any other components you want to deploy at the same time. Click through and finalise the deployment.




AWS IoT Greengrass V2 select new components for deploy

AWS IoT Greengrass V2 select new components for deploy

Once the deployment is successful you should see all green status ticks back on the Core devices screen.




AWS IoT Greengrass V2 finished deployment statuses

AWS IoT Greengrass V2 finished deployment statuses

I think that the latest Greengrass V2 update is a great step towards deployments that allow for configuration of devices to live in code and am eager to explore more ways to try it out in complex environments with more devices scaling

What do you think of the new Greengrass V2 update? I’m interested to hear you’ve used Greengrass before, or are planning to give the new update a shot! hit me up on Twitter @nathangloverAUS.

This content was originally published here.

IoT

Android and Nest are making the smart home feel smarter with Matter | Android Central

Published

on

Matter is designed to solve the smart home with a new standard that all smart homes can operate on. Google is bringing Matter compatibility to its Android and Nest ecosystems to make pairing and controlling smart home devices as easy as plugging in a USB drive.

This content was originally published here.

Continue Reading

IoT

Purina to take guesswork out of pet nutrition with IoT ‘smart bowl’ – Smart City

Published

on

“Our Purina Chekr smart bowl is managed by our Purina intelligence engine built on and powered by AWS IoT services. “This system allows pet owners … To Read More, Please Visit Source

This content was originally published here.

Continue Reading

IoT

Building Solar Energy Monitoring Systems Using IoT – floLIVE

Published

on

The global Energy market is going through substantial change, with renewable energy at an all-time high, and growing fast. While Asia-Pacific continues to dominate, interest in solar energy is growing all over the world.

According to Mordor Research, “the renewable energy installed capacity reached 2713.60 GW in 2019, and it is anticipated to reach approximately 4391.18 GW by 2026, at a CAGR of 7.13% during 2021-2026.” Below you can see how renewable energy is being adopted globally, proving that worldwide, solar power and sustainable energy solutions are a seriously hot topic. (No pun intended.) To understand more about how IoT is facilitating this growth, keep reading!

Solar Energy IoT and Smart Home Monitoring Systems

Integrating solar energy into smart homes is becoming more popular as solar panels continue to reduce in cost, but this can only happen if there are solar energy monitoring systems in place – and that’s where IoT comes in.

IoT can allow consumers and businesses to monitor the use of solar energy on a much more granular level, giving a better understanding over which appliances and services are the most energy efficient, how much power is being used, as well as insight into when and how.

For enterprises looking to facilitate and maintain solar panels and renewable energy, IoT can allow for remote maintenance, and even predictive analysis that drives down costs even further. Deep visibility can allow companies to decrease the stress on their equipment, better balancing energy loads, and alerting ahead of time to issues such as overheating.

Large-scale Solar Operations Need Remote Monitoring to Suit

While residential application is a large part of the drive to renewable energy, many energy companies are looking into increasing their solar farms, and managing power consumption and renewable energy on a much larger scale. Solar power production for energy companies can be improved exponentially with the help of IoT monitoring. As sensors become more affordable, and connectivity solutions evolve, enterprises could see huge benefits from IoT, without much risk to speak of. Here are four examples:

Maintenance: Traditionally, workers on a solar farm would need to locate and check every panel regularly to ensure that they are working as expected. These inspections can become a thing of the past when all your solar panels are connected to a centralized data source. In fact, when there’s a problem, your asset management system can let you know with a simple alert, freeing up your staff for higher value tasks. With predictive intelligence, you’re less likely to suffer as a result of outages or power issues.

Performance: By amalgamating the data that comes from your panels, grid managers will be able to spot anomalies such as solar panels or units that are under-performing, and even the reasons why, such as temperature, dust, or extreme weather conditions. Managers can then make smart changes, such as moving units, increasing the volume of cleaning, or making changes in insulation or alignment.

Security: Especially when solar panels and solar farms are in rural areas (often the case when it comes to renewable energy sources), it’s essential to have a monitoring system to keep them secure from physical theft, or even vandalism. With IoT sensors, you can establish rules for theft-related alerts, such as movement around the panels, or if a panel has been removed from the outer structure of the grid.

Forecasting: With business intelligence tools integrated into your IoT monitoring system, analytics can help you see true business growth at a much faster rate. For example, anticipate how much energy will be needed on a specific day, streamlining how much energy you use and conserve, respectively. This can improve the balance of supply and demand in the smart grid itself, saving serious zeroes off your bottom line.

When it Comes to Solar Energy… Not all IoT Technologies Are Created Equal

IoT monitoring systems have a few key needs, but top of the list is connectivity. However, this is not just any connectivity. As solar panels are often in rural areas, and sensors can often be manufactured in one location and sent to another where the energy grid is based, availability is a key issue to address first and foremost. There could be many thousands of panels or units on a large-scale solar farm, so price is also an important point to consider. One of the main contributors to cost is battery life, as the battery is often more expensive to replace than it would be to deploy new devices and sensors altogether.

LPWAN solutions and cellular IoT connectivity are a great fit for IoT monitoring in the Energy sector, with the packet size and data rates to meet these unique needs. floLIVE offers a one-of-a-kind solution in the form of software-defined connectivity, providing global connectivity through globally distributed core networks deployed in different regions. Each of these hosts a local IMSI, and they are centrally managed over the cloud. This unique approach has formed the world’s largest IMSI Library. In practice, this means that sensors can be manufactured anywhere, and IoT devices simply connect locally when they are turned on. This not only eliminates data privacy and security issues, but it also reduces the amount of time the IoT device has to be awake each time it transmits information, extending the lifespan of its battery overall.

Solar Power is the Future – and IoT Technology is Making That Happen

The IEA expects solar energy to play the biggest role in jumpstarting fresh growth in global renewable energy because falling costs are already below retail electricity prices in most countries. The cost of solar power is expected to decline by a further 15% to 35% by 2024, spurring further growth over the second half of the decade.”

The world is ready for solar energy, but without an IoT solution in place for remote monitoring, the benefits are going to be limited for today’s enterprises.

Ready to discuss your roadmap for sustainable energy augmented by IoT technology? Let’s talk.

This content was originally published here.

Continue Reading

Trending

AutomateMyHome

Subscribe to AMH Daily Updates

Get the best news, expert tips and product reviews everyday!