diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..903cb24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store + +helper +my-iot diff --git a/helper.go b/helper.go index dadac0e..214cd06 100644 --- a/helper.go +++ b/helper.go @@ -3,9 +3,32 @@ package main import ( "github.com/aws/aws-sdk-go/aws" d "github.com/aws/aws-sdk-go/service/dynamodb" + da "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" "github.com/aws/aws-sdk-go/service/dynamodb/expression" ) +// GetDevice is to get a device from id +func GetDevice(svc *d.DynamoDB, deviceID string) (Device, error) { + var device Device + input := &d.GetItemInput{ + Key: map[string]*d.AttributeValue{ + "device": { + S: aws.String(deviceID), + }, + }, + TableName: aws.String("iot-item"), + } + result, err := svc.GetItem(input) + if err != nil { + return device, err + } + err = da.UnmarshalMap(result.Item, &device) + if err != nil { + return device, err + } + return device, nil +} + // GetDevices is to get all devices we know func GetDevices(svc *d.DynamoDB) (*d.ScanOutput, error) { @@ -31,6 +54,7 @@ func GetHistory(svc *d.DynamoDB, deviceID string, limit int64) (*d.QueryOutput, qProj := expression.NamesList( expression.Name("device"), expression.Name("timestamp"), + expression.Name("info"), expression.Name("data")) qBuilder := expression.NewBuilder().WithKeyCondition(keyCond).WithProjection(qProj) diff --git a/html/home.html b/html/home.html index 74bd0a1..5d53757 100644 --- a/html/home.html +++ b/html/home.html @@ -27,17 +27,38 @@