greengo
greengo copied to clipboard
Write to Dynamodb
This is a bit odd and may require me forking but worth raising anyho, what about the option to write to a dynamodb, as I keep a list of my device in a device-table for access via appsync and user mapping
something like
DynamoTable: gen-devices
# in __init__
self._dynamodb = s.resource('dynamodb')
# in create
if 'DynamoTable' in self.group:
self._create_table_entry()
#create table function
def _create_table_entry(self):
thingTable = self._dynamodb.Table(self.group['tables']['thingTable'])
self.group['thing']['id'] = self.id
thingTable.put_item(
Item=self.thing
)
Also while on odd user cases, the name for your group, anychance this could be auto generated, as we will deploy to potential thousands of devices and save adjusting the yaml everytime
something like
# in __init__
self.state = _load_state()
if self.state:
self.uuid = self.state['id']
else:
self.uuid = str(uuid.uuid4())
self.name = "G"+self.uuid
# in create
self.state['id'] = self.uuid
Just some ideas, I can fork when you finish v2 but it would be nice to keep using the original repo
happy to make pull requests on both issues if you are interested
I'd look at solving your case differently. Given you want to use device info from appsync, you could 1) use IoT API to query device shadows or 2) populate dynamoDB on MQTT triggers when device is deployed, with IoT rules.
What I think we DO need to add here is rule definitions right in greengo.yaml
.
Yeah I do save readings from a device with IoT rules, but on init I save out my device config to dynamodb, that way I can map cognito users against devices they register to (also I can save third party integration settings against a device in dynamodb allowing a user to configure there devices). The "save reading" IoT Lambda action references the dynamodb device to pick up any third party integrations and calls corresponding lambdas if required when saving a reading. You are right though, I would very much like to incorporate device shadow when setting set points and calibration data