Hello!
Im trying to deploy a component to read battery values from a UPS board attached to Raspberry pi model 3B+ using I2C protocol. For this purpose, im using the smbus library with python, and reading the 0x36 address
. The code runs with no problem, but when i try to deploy as component using greengrass, doesn't shows when lists all the components. The artifact and recipe docs are showed:
Recipe:
{
"RecipeFormatVersion": "2020-01-25",
"ComponentName": "com.example.battery",
"ComponentVersion": "1.0.0",
"ComponentDescription": "My first AWS IoT Greengrass component.",
"ComponentPublisher": "Amazon",
"ComponentConfiguration": {
"DefaultConfiguration": {
"Message": "world"
}
},
"Manifests": [
{
"Platform": {
"os": "linux"
},
"Lifecycle": {
"RequiresPrivilege": true,
"Install": "python3 -m pip install --user smbus",
"Run": "python3 -u {artifacts:path}/battery.py \"{configuration:/Message}\""
}
}
]
}
Artifact:
# ! / Usr / bin / env python
import struct
import smbus
import time
def readVoltage(bus):
"This function returns as float Hat via the voltage from the Raspi UPS the \provided SMBus object"
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct .unpack("<H", struct.pack("> H", read))[0]
voltage = swapped * 1.25 / 1000 / 16
return voltage
def readCapacity(bus):
"This function returns as a float the remaining capacity of the battery connected to the Raspi UPS Hat via the provided SMBus object "
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct .pack("> H", read))[0]
capacity = swapped / 256
return capacity
bus = smbus .SMBus(1) # 0 = / dev / i2c-0 (port I2C0), 1 = / dev / i2c-1 (port I2C1)
while True:
print("++++++++++++++++++++")
print("Voltage:% 5.2fV" % readVoltage(bus))
print("Battery:% 5i %%" % readCapacity(bus))
if readCapacity(bus) == 100:
print("Battery FULL")
if readCapacity(bus) < 20:
print("Battery LOW")
print("++++++++++++++++++++")
time . sleep(2)
The code for deploy de component is the following:
sudo /greengrass/v2/bin/greengrass-cli deployment create
--recipeDir ~/greengrassv2/recipes
--artifactDir ~/greengrassv2/artifacts
--merge "com.example.battery=1.0.0"
And the error in greengrass.log
is the following:
2023-03-28T15:32:51.103Z [ERROR] (pool-2-thread-12) com.aws.greengrass.deployment.DeploymentService: Deployment task failed with following errors. {DeploymentId=42b70947-9b4a-4732-ac16-de41b80ede7f, detailed-deployment-status=FAILED_NO_STATE_CHANGE, deployment-error-types=[REQUEST_ERROR], GreengrassDeploymentId=42b70947-9b4a-4732-ac16-de41b80ede7f, serviceName=DeploymentService, currentState=RUNNING, deployment-error-stack=[DEPLOYMENT_FAILURE, NO_AVAILABLE_COMPONENT_VERSION, COMPONENT_VERSION_REQUIREMENTS_NOT_MET]}
com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException: No local or cloud component version satisfies the requirements Check whether the version constraints conflict and that the component exists in your AWS account with a version that matches the version constraints. If the version constraints conflict, revise deployments to resolve the conflict. Component com.example.battery version constraints: LOCAL_DEPLOYMENT requires =1.0.0.
at com.aws.greengrass.componentmanager.ComponentManager.negotiateVersionWithCloud(ComponentManager.java:229)
at com.aws.greengrass.componentmanager.ComponentManager.resolveComponentVersion(ComponentManager.java:164)
at com.aws.greengrass.componentmanager.DependencyResolver.lambda$resolveDependencies$2(DependencyResolver.java:125)
at com.aws.greengrass.componentmanager.DependencyResolver.resolveComponentDependencies(DependencyResolver.java:221)
at com.aws.greengrass.componentmanager.DependencyResolver.resolveDependencies(DependencyResolver.java:123)
at com.aws.greengrass.deployment.DefaultDeploymentTask.lambda$call$2(DefaultDeploymentTask.java:125)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Can you try using a relative or an absolute path for the artifact and recipe folders in the
greengrass-cli
command. Do not use~
. Ie: