aws-samples / aws-greengrass-samples

Samples for AWS Greengrass
MIT No Attribution
96 stars 68 forks source link

Environmental Sensors Compatible with AWS Greengrass #33

Closed silverage01 closed 4 years ago

silverage01 commented 4 years ago

An AWS Premium Support Engineer (KATIKI S.) asked me to post this question here as it was not within the scope of the Support team.

Are there any environmental sensor manufacturers that are certified compatible with Greengrass? I typically use SeeedStudio Grove sensors for environmental monitoring, but they are not compatible with AWS Greengrass. I am using Raspberry Pi 4 as a board.

Thanks!

MikeDombo commented 4 years ago

Hi Silverage01, can you tell us what makes them incompatible? Greengrass can be configured in many ways to give your lambda the same access as any normal process running on the Pi. So if those sensors are able to work when run outside of the Greengrass context, we ought to be able to find a way to make them work.

silverage01 commented 4 years ago

Hi Mike,

The Grove sensors are based in Python, and use a module called Grove.py. They plug into a Grove Base Hat which sits on a Raspberry Pi. I have used these successfully in the past with IoT Core service, but there is a limitation with Greengrass:

https://www.seeedstudio.com/category/Grove-c-1003.html https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi/

From the AWS Premium Support Engineer:

I have done through research about the complete use-case again and found out that the Lambda function will not able to access the GPIO’s directly. As per the Grove architecture ‘Grove.py’ module is used to communicate with the GPIO’s and because of this the Connectors will not be able to integrate with the Grove based GPIO’s. Due to this we will not be able to use the Connectors and the Lambda function to access the Grove base GPIO’s and achieve the use-case. ...... As we understand that GPIO modules of the RPI and Grove modules will be depend up the Operating System. Because of this the Lambda function will not be able to access the Raspberry Pi GPIO and the Grove Hat GPIOs. The Greengrass connector is supporting only RPi.GPIO module to communicate with the GIPO’s of the Raspberry Pi. ...... We are not able to integrate the Grove Base Hat with the Greengrass core as we need to use the ‘Grove.py’ module to access the sensors connected to the hat. Because of this we can not use Grove sensor with Grove Base Hat.

MikeDombo commented 4 years ago

It is correct that the pre-built connector may not be able to access your Grove sensor. However, you most certainly can write your own lambda to use the sensor. You may need to look into Greengrass Local Resource Access (https://docs.aws.amazon.com/greengrass/latest/developerguide/access-local-resources.html). If you do not need the extra security that containers provide, then you may also use "process mode" (https://docs.aws.amazon.com/greengrass/latest/developerguide/lambda-group-config.html#lambda-containerization-groupsettings). Process mode runs your lambda just as a regular process just as you would do yourself. So, if you can write a python script to access the sensors and run it yourself, you ought to be able to turn that into a lambda that Greengrass can run.

silverage01 commented 4 years ago

The guidance that was given to me by support was to develop a workaround solution akin to Virtual GPIOs. This kind of low level programming is something that I am hoping to avoid. Writing a Lambda function to integrate with the sensors was what I expected, but not this kind of solution. Thats why I asked if there are any other environmental sensors that are proven to be compatible with Greengrass.

...... Since, the Lambda function will not be access the Grove based sensors or the GPIO's of the Raspberry Pi directly, we can send the data to another GPIO pins using a process, the process will act as virtual sensor and the Connectors will receive the data from the GPIO’s. Hence, I request you to configure a process to receive the data from the Grove based GPIO’s and sending them to the Raspberry Pi GPIO, configure the connectors to collect data from the GPIO’s and the Lambda function will send the AWS IoT topic. ...... I referred a process as virtual sensors which access the data from the GPIO pins and sending the data to another GPIO pins which are configured in the connectors. .......

MikeDombo commented 4 years ago

The GPIO connector is very basic as it only allows reading and writing GPIO and nothing higher level such as SPI or I2C. No environmental sensor, such as a temperature sensor, would be readable in this way. Any sensor like that would require a higher level protocol on top of the digital GPIO, and our Connector has no such support.

You will need to write your own lambda to read from the sensor, publish the data to AWS IoT, then repeat. Or indeed whatever logic you want to put. But this is not something that can be done with the Greengrass GPIO Connector, no matter what sensors you have.

silverage01 commented 4 years ago

I guess my expectation was that the Lambda in the Greengrass group should follow the format in the Example at the bottom of this page:

https://docs.aws.amazon.com/greengrass/latest/developerguide/raspberrypi-gpio-connector.html

What you are saying is that all environmental sensor integration with Greengrass will require more programming than basic configuration of the GPIO connector? I am ok with writing a Lambda to consume data from the sensor and send it to an AWS IoT endpoint. But if it requires what I consider low-level hardware programming, then I am not sure that Greengrass is the right solution for me.

MikeDombo commented 4 years ago

Looks like you should be able to just use the Grove Python library (https://github.com/Seeed-Studio/grove.py). Therefore, nothing low-level should be required; just use the library provided by Seeed.

Again, the GPIO Connector can only read and write the GPIO pins on the Pi as high/low. So if you have a sensor which is only binary (on/off), then the Connector should work fine. But, if the sensors that you are interested in using are more complex, like humidity, temperature, or pressure, then the GPIO Connector will not be able to read the values for you.

silverage01 commented 4 years ago

Here are two sensors I am working with:

https://wiki.seeedstudio.com/Grove-Temperature_and_Humidity_Sensor_Pro/ https://wiki.seeedstudio.com/Grove-I2C_UV_Sensor-VEML6070/

They are plugged into the Grove Base Hat for Raspberry Pi. I was planning on reading the sensor data directly from the GPIO pins as the Hat sockets map to GPIO pins.

MikeDombo commented 4 years ago

You don't need to do anything with the GPIO pins directly, you can simply use the existing Grove GPIO library.

See this example from Grove for using your temperature and humidity sensors: https://github.com/Seeed-Studio/grove.py/blob/master/doc/README.md#temperature--humidity-sensordht11

Here's the example for the UV sensor: https://github.com/Seeed-Studio/grove.py/blob/master/grove/grove_uv_sensor.py

silverage01 commented 4 years ago

Temperature and Humidity Sensor Pro is here, separate from Grove.py:

https://github.com/Seeed-Studio/Seeed_Python_DHT/blob/master/examples/dht_simpleread.py

The UV sensor code is as you indicated. I was able to take this code and modify it to integrate the two sensors directly with AWS IoT Core by including the AWSIoTPythonSDK. According to the support engineer, the barrier with Greengrass seemed more about Lambdas inability to work with Grove.py and read from GPIO directly, whether in container mode or not.

MikeDombo commented 4 years ago

Your lambdas absolutely can work with the Grove sensors. The only thing that does not work is the prebuilt Greengrass GPIO Connector cannot work with those sensors.

If you have trouble writing your own lambda to work with the sensors, then let us know, but it definitely can work.

silverage01 commented 4 years ago

Grove has their own GPIO library, which I think helped to contribute to the confusion. Sounds like the right approach is just to use that library (if needed), and do not use the Greengrass GPIO Connector?

https://github.com/Seeed-Studio/grove.py/tree/master/grove/gpio

MikeDombo commented 4 years ago

Yes, just write a Python lambda for yourself which uses whatever Grove libraries are necessary.

Do not use the Greengrass GPIO Connector as it cannot do what you require.