Skip to content

Commit 4faa647

Browse files
author
Jinesh Varia
committed
MediaTek Linkit One
1 parent 1138e9e commit 4faa647

22 files changed

+2273
-16
lines changed

NOTICE.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version 1 of Experimental AWS SDK for Arduino, and Samples
1+
Version 1 of Experimental AWS SDK for Arduino, and Samples
22

33
Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. 
44

@@ -14,6 +14,7 @@ THIRD PARTY COMPONENTS
1414
This software includes third party software subject to the following copyrights:
1515

1616
- jsmn, minimalistic JSON parser in C - Copyright (c) 2010 Serge A. Zaitsev. Includes minor modifications.
17-
- Portable C++ Hashing Library (SHA256 files only) - Copyright (c) 2014 Stephan Brumme. Includes minor modifications.
17+
- Portable C++ Hashing Library (SHA256 files only) - Copyright (c) 2014 Stephan Brumme. Includes minor modifications.
18+
1819

1920
The licenses for these third party components are included in LICENSE

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ The SDK is extensible to non-Arduino-compatible devices by implementing the inte
1212
* /sparkcore contains Spark IO Core device-specific implementations
1313
* /edison contains Intel Edison device-specfic implementations
1414
* /galileo contains Intel Galileo device-specific implementations
15+
* /mediatek contains MediaTek LinkIt One device-specific implementations
16+
1517

1618
Depending on the device that you are working, Simply copy the those device-specific implementations to the Common directory so you can test out your samples using Arduino IDE.
1719

@@ -61,7 +63,11 @@ You can follow the steps below to get the tables set up with the right values, c
6163

6264
This step is different for the Spark Core and Intel Galileo.
6365

64-
#### Intel Galileo/Edison
66+
#### Connected Maraca Sample (Edison/SparkCore/MediaTek)
67+
68+
follow the step by step guide: http://bit.ly/aws-iot-hackseries
69+
70+
#### Intel Galileo/Edison Sample
6571

6672
With Galileo or Edison, you should be using the Arduino IDE from Intel as it includes Galileo and Edison libraries. [Link to Intel-Arduino IDE](https://communities.intel.com/docs/DOC-22226).
6773

@@ -72,7 +78,7 @@ Move all of the files from the SDK's `src/common` directory into the `AWSArduino
7278
Create a new sketch with the Arduino IDE and copy and paste the sample code into it.
7379

7480

75-
#### Spark IO Core
81+
#### Spark IO Core Sample
7682

7783
This assumes you already have your Spark set up and are able to program it with Spark Build. If you do not, head over to [Spark's website](http://docs.spark.io/).
7884

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
#include <EdisonAWSImplementations.h>
2+
#include "AWShelperFunctions.h"
3+
#include "HardwareFunctions.h"
4+
#include "keys.h"
5+
#include <Utils.h>
6+
7+
AmazonSNSClient snsClient;
8+
AmazonDynamoDBClient ddbClient;
9+
AmazonKinesisClient kClient;
10+
11+
/* Device independent implementations required for AmazonDynamoDBClient to
12+
* function. */
13+
EdisonHttpClient httpClient;
14+
//kinesis
15+
EdisonHttpCurlClient httpCurlClient;
16+
EdisonDateTimeProvider dateTimeProvider;
17+
18+
PublishInput publishInput;
19+
GetItemInput getItemInput;
20+
PutItemInput putItemInput;
21+
AttributeValue hashKey;
22+
AttributeValue rangeKey;
23+
ActionError actionError;
24+
25+
void SNSClient_Setup() {
26+
snsClient.setAWSRegion(AWS_REGION);
27+
snsClient.setAWSEndpoint(AWS_ENDPOINT);
28+
snsClient.setAWSSecretKey(awsSecKey);
29+
snsClient.setAWSKeyID(awsKeyID);
30+
snsClient.setHttpClient(&httpClient);
31+
snsClient.setDateTimeProvider(&dateTimeProvider);
32+
}
33+
34+
void DynamoBDClient_Setup() {
35+
ddbClient.setAWSRegion(AWS_REGION);
36+
ddbClient.setAWSEndpoint(AWS_ENDPOINT);
37+
ddbClient.setAWSSecretKey(awsSecKey);
38+
ddbClient.setAWSKeyID(awsKeyID);
39+
ddbClient.setHttpClient(&httpClient);
40+
ddbClient.setDateTimeProvider(&dateTimeProvider);
41+
}
42+
43+
void KinesisClient_Setup() {
44+
kClient.setAWSRegion(AWS_REGION);
45+
kClient.setAWSEndpoint(AWS_ENDPOINT);
46+
kClient.setAWSSecretKey(awsSecKey);
47+
kClient.setAWSKeyID(awsKeyID);
48+
kClient.setHttpClient(&httpCurlClient);
49+
kClient.setDateTimeProvider(&dateTimeProvider);
50+
}
51+
52+
void putDynamoDb() {
53+
// Put device & datestamp record in DynamoDB table
54+
// Create an Item.
55+
AttributeValue deviceIdValue;
56+
deviceIdValue.setS(HASH_KEY_VALUE);
57+
AttributeValue timeValue;
58+
// Getting current time for Time attribute.
59+
timeValue.setN(dateTimeProvider.getDateTime());
60+
AttributeValue deviceValue;
61+
deviceValue.setS(ATTRIBUTE_VALUE);
62+
63+
MinimalKeyValuePair<MinimalString, AttributeValue> att1(HASH_KEY_NAME, deviceIdValue);
64+
MinimalKeyValuePair<MinimalString, AttributeValue> att2(RANGE_KEY_NAME, timeValue);
65+
MinimalKeyValuePair<MinimalString, AttributeValue> att3(ATTRIBUTE_NAME, deviceValue);
66+
MinimalKeyValuePair<MinimalString, AttributeValue> itemArray[] = { att1,
67+
att2, att3 };
68+
69+
// Set values for putItemInput.
70+
putItemInput.setItem(MinimalMap<AttributeValue>(itemArray, 3));
71+
putItemInput.setTableName(TABLE_NAME);
72+
73+
// perform putItem and check for errors.
74+
PutItemOutput putItemOutput = ddbClient.putItem(putItemInput, actionError);
75+
switch (actionError) {
76+
case NONE_ACTIONERROR:
77+
Serial.println("DynamoDB PutItem succeeded!");
78+
break;
79+
case INVALID_REQUEST_ACTIONERROR:
80+
Serial.print("ERROR: ");
81+
Serial.println(putItemOutput.getErrorMessage().getCStr());
82+
break;
83+
case MISSING_REQUIRED_ARGS_ACTIONERROR:
84+
Serial.println(
85+
"ERROR: Required arguments were not set for PutItemInput");
86+
break;
87+
case RESPONSE_PARSING_ACTIONERROR:
88+
Serial.println("ERROR: Problem parsing http response of PutItem");
89+
break;
90+
case CONNECTION_ACTIONERROR:
91+
Serial.println("ERROR: Connection problem");
92+
break;
93+
}
94+
}
95+
96+
void putKinesis(double realAccelX, double realAccelY, double realAccelZ) {
97+
// light the grove LED to indicate posting to AWS service
98+
99+
PutRecordInput putRecordInput;
100+
putRecordInput.setStreamName(streamName);
101+
102+
char buffer[255];
103+
String dataSource;
104+
dataSource = String("{\"device_id\":\"");
105+
dataSource += HASH_KEY_VALUE;
106+
dataSource += String("\",\"time\":");
107+
dataSource += dateTimeProvider.getDateTime();
108+
dataSource += String(",\"device\":\"");
109+
dataSource += ATTRIBUTE_VALUE;
110+
dataSource += String("\",\"sensors\":[{\"telemetryData\": {\"xval\":");
111+
sprintf(buffer, "%f", realAccelX);
112+
dataSource += buffer;
113+
dataSource += String(",\"yval\":");
114+
sprintf(buffer, "%f", realAccelY);
115+
dataSource += buffer;
116+
dataSource += String(",\"zval\":");
117+
sprintf(buffer, "%f", realAccelZ);
118+
dataSource += buffer;
119+
dataSource += String("}}]}");
120+
dataSource.toCharArray(buffer, 255);
121+
Serial.println(buffer);
122+
Serial.println(dateTimeProvider.getDateTime());
123+
char* data = base64Encode(buffer);
124+
putRecordInput.setData(data);
125+
delete[] data;
126+
putRecordInput.setPartitionKey(partitionKey);
127+
128+
// simple blind putRecord, no way to read output of System call for now
129+
kClient.putRecord(putRecordInput, actionError);
130+
Serial.println("\nKinesis record posted to Stream");
131+
// switch off the Grove LED again - message posted
132+
133+
}
134+
135+
void putSns() {
136+
137+
// set datetime as the message to TARGET_ARN
138+
MinimalString dateTime(dateTimeProvider.getDateTime());
139+
dateTimeProvider.sync(dateTime.getCStr());
140+
141+
// Delivery attempt to Amazon SNS.
142+
publishInput.setMessage(dateTime);
143+
publishInput.setTargetArn(TARGET_ARN);
144+
PublishOutput publishOutput = snsClient.publish(publishInput, actionError);
145+
Serial.print("Sent message ID: ");
146+
Serial.println(publishOutput.getMessageId().getCStr());
147+
}
148+
149+
150+
151+
void indicateServiceThroughLED_blink_Buzzer(AWS_Service_ID service) {
152+
153+
int blinkCount = 0;
154+
155+
switch (service) {
156+
157+
case KINESIS:
158+
blinkCount = 1;
159+
break;
160+
161+
case DYNAMO_DB:
162+
blinkCount = 2;
163+
break;
164+
165+
case SNS:
166+
blinkCount = 3;
167+
break;
168+
169+
default:
170+
blinkCount = 10;
171+
break;
172+
}
173+
blinkGroveLed(blinkCount);
174+
175+
}
176+
177+
178+
AWS_Service_ID changeService(AWS_Service_ID currentServiceId) {
179+
AWS_Service_ID nextServiceId;
180+
181+
Serial.print("Button pressed - changing mode. New mode: ");
182+
183+
nextServiceId = (AWS_Service_ID)(currentServiceId + 1);
184+
if (nextServiceId >= END_NOSERVICE) {
185+
nextServiceId = KINESIS;
186+
}
187+
188+
indicateServiceThroughLED_blink_Buzzer(nextServiceId);
189+
190+
switch (nextServiceId) {
191+
case 0:
192+
Serial.println("Kinesis");
193+
break;
194+
case 1:
195+
Serial.println("DynamoDB");
196+
break;
197+
case 2:
198+
Serial.println("SNS");
199+
break;
200+
}
201+
return nextServiceId;
202+
}
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
243+
244+
245+
246+
247+
248+
249+
250+
251+
252+
253+
254+
255+
256+
257+
258+
259+
260+
261+
262+
263+
264+
265+
266+
267+
268+

0 commit comments

Comments
 (0)