Skip to content

Commit 2e80e59

Browse files
author
ZENG
committed
Added compatibility for Linino openWRT embedded Linux OS. Refactored file names for credential/codebase setup shell scripts.
1 parent f323bad commit 2e80e59

12 files changed

+118
-49
lines changed

AWS-IoT-Arduino-Yun-Library/aws_iot_config_SDK.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#ifndef config_h
1717
#define config_h
1818

19-
#define MAX_BUF_SIZE 256 // maximum number of bytes to publish/receive
20-
#define MAX_SUB 15 // maximum number of subscribe
21-
#define CMD_TIME_OUT 100 // maximum time to wait for feedback from AR9331, 100 = 10 sec
22-
#define MAX_SHADOW_TOPIC_LEN 64 // maximum length for shadow topic, the metadata length for shadow topic is 32, make sure your thing name length plus that does not exceed this limit
19+
#define MAX_BUF_SIZE 256 // maximum number of bytes to publish/receive
20+
#define MAX_SUB 15 // maximum number of subscribe
21+
#define CMD_TIME_OUT 100 // maximum time to wait for feedback from AR9331, 100 = 10 sec
22+
#define MAX_SHADOW_TOPIC_LEN 64 // maximum length for shadow topic, the metadata length for shadow topic is 32, make sure your thing name length plus that does not exceed this limit
2323

2424
#endif

AWS-IoT-Arduino-Yun-Library/aws_iot_error.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ typedef enum {
3333
SHADOW_GET_ERROR = -13,
3434
SHADOW_DELETE_ERROR = -14,
3535
CONFIG_ERROR = -15,
36-
OUT_OF_SKETCH_SUBSCRIBE_MEMORY = -16
36+
OUT_OF_SKETCH_SUBSCRIBE_MEMORY = -16,
37+
SERIAL1_COMMUNICATION_ERROR = -17
3738
} IoT_Error_t;
3839

39-
#endif
40+
#endif
41+

AWS-IoT-Arduino-Yun-Library/aws_iot_mqtt.cpp

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,91 @@
2020
#include "string.h"
2121
#include "ctype.h"
2222

23-
#define linux_baud 250000
23+
#define LINUX_BAUD_DEFAULT 250000
24+
#define LINUX_BAUD_LININO 115200
2425
#define SHADOW_TOPIC_FIXED_LEN 32 // strlen("$aws/things/") + strlen("/shadow/update/delta")
2526
#define RETURN_KEY 13 // ASCII code for '\r'
2627
#define NEXTLINE_KEY 10 // ASCII code for '\n'
28+
#define MAX_NUM_PARA 7 // Maximum number of parameters in protocol communication
2729

2830
const char* OUT_OF_BUFFER_ERR_MSG = "OUT OF BUFFER SIZE";
2931

30-
IoT_Error_t aws_iot_mqtt_client::setup(char* client_id, bool clean_session, MQTTv_t MQTT_version) {
32+
// Choose different baudrate for different version of openWRT OS
33+
Baud_t aws_iot_mqtt_client::find_baud_type() {
34+
Baud_t rc_type = BAUD_TYPE_UNKNOWN;
35+
// 1st attempt
36+
Serial1.begin(LINUX_BAUD_DEFAULT);
37+
while(!Serial1);
38+
exec_cmd("\n", true, false); // jump over the welcoming prompt for Open WRT
39+
delay(1000); // in case this is the first boot-up
40+
int i;
41+
for(i = 0; i < MAX_NUM_PARA + 1; i++) {
42+
// exit the previous python process and jump over the half-baked protocol communication
43+
exec_cmd("~\n", true, false);
44+
}
45+
delay(1500); // delay 1500 ms for all related python script to exit
46+
47+
exec_cmd("uname\n", true, false); // check OS version
48+
if(strncmp(rw_buf, "Linux", 5) != 0) { // Not an Arduino?
49+
Serial1.begin(LINUX_BAUD_LININO);
50+
while(!Serial1);
51+
exec_cmd("\n", true, false); // jump over the welcoming prompt for Open WRT
52+
delay(1000); // in case this is the first boot-up
53+
int i;
54+
for(i = 0; i < MAX_NUM_PARA + 1; i++) {
55+
// exit the previous python process and jump over all possible half-baked protocol communication
56+
exec_cmd("~\n", true, false);
57+
}
58+
delay(1500); // delay 1500 ms for all related python script to exit
59+
60+
exec_cmd("uname\n", true, false); // check OS version
61+
if(strncmp(rw_buf, "Linux", 5) != 0) {
62+
// No more board types to try
63+
}
64+
else {rc_type = BAUD_TYPE_LININO;}
65+
}
66+
else {rc_type = BAUD_TYPE_ARDUINO;}
67+
68+
return rc_type;
69+
}
70+
71+
IoT_Error_t aws_iot_mqtt_client::setup_exec(char* client_id, bool clean_session, MQTTv_t MQTT_version) {
72+
// Serial1 is started before this call
3173
IoT_Error_t rc = NONE_ERROR;
32-
if(client_id == NULL) {rc = NULL_VALUE_ERROR;}
33-
else if(strlen(client_id) >= MAX_BUF_SIZE) {rc = OVERFLOW_ERROR;}
34-
else {
35-
my_client_id = client_id;
36-
// Start Serial1
37-
Serial1.begin(linux_baud);
38-
while(!Serial1); // blocking until Serial1 is ready
74+
exec_cmd("cd /root\n", false, false);
75+
exec_cmd("python aws_iot_mqtt_client.py\n", false, false);
3976

40-
exec_cmd("cd .\n", false, false); // placeholder: jump over the welcoming prompt for Open WRT
41-
exec_cmd("cd /root\n", false, false);
42-
exec_cmd("~\n", true, false); // exit the previous python process
43-
delay(1000); // delay 1000 ms for all related python script to exit
44-
exec_cmd("python aws_iot_mqtt_client.py\n", false, false);
77+
// Create obj
78+
exec_cmd("i\n", false, false);
4579

46-
// Create obj
47-
exec_cmd("i\n", false, false);
80+
sprintf(rw_buf, "%s\n", client_id);
81+
exec_cmd(rw_buf, false, false);
4882

49-
sprintf(rw_buf, "%s\n", client_id);
50-
exec_cmd(rw_buf, false, false);
83+
int num_temp = clean_session ? 1 : 0;
84+
sprintf(rw_buf, "%d\n", num_temp);
85+
exec_cmd(rw_buf, false, false);
5186

52-
int num_temp = clean_session ? 1 : 0;
53-
sprintf(rw_buf, "%d\n", num_temp);
54-
exec_cmd(rw_buf, false, false);
87+
sprintf(rw_buf, "%u\n", MQTT_version);
88+
exec_cmd(rw_buf, true, false);
5589

56-
sprintf(rw_buf, "%u\n", MQTT_version);
57-
exec_cmd(rw_buf, true, false);
90+
if(strncmp(rw_buf, "I T", 3) != 0) {rc = SET_UP_ERROR;}
5891

59-
if(strncmp(rw_buf, "I T", 3) != 0) {rc = SET_UP_ERROR;}
92+
return rc;
93+
}
94+
95+
IoT_Error_t aws_iot_mqtt_client::setup(char* client_id, bool clean_session, MQTTv_t MQTT_version) {
96+
IoT_Error_t rc = NONE_ERROR;
97+
if(client_id == NULL) {rc = NULL_VALUE_ERROR;}
98+
else if(strlen(client_id) >= MAX_BUF_SIZE) {rc = OVERFLOW_ERROR;}
99+
// No input error below this line
100+
else {
101+
my_client_id = client_id;
102+
Baud_t baud_type = find_baud_type(); // Find out baud type
103+
// Communication failed due to baud rate issue
104+
if(BAUD_TYPE_UNKNOWN == baud_type) {rc = SERIAL1_COMMUNICATION_ERROR;}
105+
else {
106+
rc = setup_exec(client_id, clean_session, MQTT_version);
107+
}
60108
}
61109

62110
return rc;

AWS-IoT-Arduino-Yun-Library/aws_iot_mqtt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ typedef enum {
2626
MQTTv311 = 4
2727
} MQTTv_t;
2828

29+
typedef enum {
30+
BAUD_TYPE_UNKNOWN = -1,
31+
BAUD_TYPE_ARDUINO = 0,
32+
BAUD_TYPE_LININO = 1
33+
} Baud_t;
34+
2935
typedef void(*message_callback)(char*, int);
3036

3137
class aws_iot_mqtt_client {
@@ -70,6 +76,8 @@ class aws_iot_mqtt_client {
7076
bool timeout_flag; // Is there a timeout when executing RPC
7177
unsigned int ThingShadow_req_num; // sequence number for ThingShadow request
7278
IoT_Error_t base_subscribe(char* topic, int qos, message_callback cb, int is_delta);
79+
Baud_t find_baud_type();
80+
IoT_Error_t setup_exec(char* client_id, bool clean_session, MQTTv_t MQTT_version);
7381
void exec_cmd(const char* cmd, bool wait, bool single_line);
7482
bool is_num(char* src);
7583
};

AWS-IoT-Arduino-Yun-Library/aws_iot_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 0
21-
#define VERSION_PATCH 1
21+
#define VERSION_PATCH 2
2222
#define VERSION_TAG ""
2323

2424
#endif

AWS-IoT-Arduino-Yun-Library/keywords.txt

100755100644
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
aws_iot_mqtt KEYWORD1
22
aws_iot_mqtt_client KEYWORD1
3-
aws_iot_version KEYWORD1
4-
aws_iot_config KEYWORD1
5-
setup KEYWORD2
6-
config KEYWORD2
7-
connect KEYWORD2
8-
publish KEYWORD2
9-
subscribe KEYWORD2
10-
unsubscribe KEYWORD2
11-
disconnect KEYWORD2
12-
yield KEYWORD2
13-
shadow_init KEYWORD2
3+
aws_iot_version KEYWORD1
4+
aws_iot_config KEYWORD1
5+
setup KEYWORD2
6+
config KEYWORD2
7+
connect KEYWORD2
8+
publish KEYWORD2
9+
subscribe KEYWORD2
10+
unsubscribe KEYWORD2
11+
disconnect KEYWORD2
12+
yield KEYWORD2
13+
shadow_init KEYWORD2
1414
shadow_register_delta_func KEYWORD2
1515
shadow_unregister_delta_func KEYWORD2
16-
shadow_get KEYWORD2
17-
shadow_update KEYWORD2
18-
shadow_delete KEYWORD2
16+
shadow_get KEYWORD2
17+
shadow_update KEYWORD2
18+
shadow_delete KEYWORD2

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.0.2 (November 5, 2015)
2+
Features:
3+
4+
N/A
5+
6+
Bugfixes/Improvements:
7+
8+
* Added compatibility for Linino openWRT embedded Linux OS (BusyBox v1.19.4 2015-10-03 14:03:26 CEST)
9+
* Refactored file names for credential/codebase upload shell scripts and environment setup shell scripts
10+
111
# 1.0.1 (November 3, 2015)
212
Features:
313

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ For Arduino IDE installation on Linux, please visit [here](http://playground.ard
4343
2. Make sure your computer is connected to the same network (local IP address range).
4444
3. Download the AWS IoT CA file from [here](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem).
4545
4. Put your AWS IoT CA file, private key and certificate into `AWS-IoT-Arduino-Yun-SDK/certs`.
46-
5. Under `AWS-IoT-Arduino-Yun-SDK`, Modify `mySCP.sh` and `mySETUP.sh` and replace `[your_boards_IP]` with your board’s IP address and `[your_boards_IP]` with your password (default for Arduino Yún: “arduino”).
47-
6. Open a terminal, cd to `AWS-IoT-Arduino-Yun-SDK`. Do `chmod 755 mySCP.sh` and execute it as `./mySCP.sh`.
46+
5. Under `AWS-IoT-Arduino-Yun-SDK`, Modify `codebase_upload.sh` and `environment_setup.sh` and replace `[your_boards_IP]` with your board’s IP address and `[your_boards_IP]` with your password (default for Arduino Yún: “arduino”).
47+
6. Open a terminal, cd to `AWS-IoT-Arduino-Yun-SDK`. Do `chmod 755 codebase_upload.sh` and execute it as `./codebase_upload.sh`.
4848
This will upload the python code and keys, CA files and certificates to openWRT running on the more powerful microcontroller on you Arduino Yún board.
49-
7. In the same directory, do `chmod 755 mySETUP.sh` and execute it as `./mySETUP.sh`.
49+
7. In the same directory, do `chmod 755 environment_setup.sh` and execute it as `./environment_setup.sh`.
5050
This will download and install libraries for openWRT to implement the necessary scripting environment as well as communication protocols.
5151

5252
Step 7 can take 15-20 minutes for the device to download and install the required packages (distribute, python-openssl, pip, paho-mqtt).
@@ -582,7 +582,8 @@ The following error codes are defined in `AWS-IoT-Arduino-Yun-Library/aws_iot_er
582582
SHADOW_GET_ERROR = -13,
583583
SHADOW_DELETE_ERROR = -14,
584584
CONFIG_ERROR = -15,
585-
OUT_OF_SKETCH_SUBSCRIBE_MEMORY = -16
585+
OUT_OF_SKETCH_SUBSCRIBE_MEMORY = -16,
586+
SERIAL1_COMMUNICATION_ERROR = -17
586587
} IoT_Error_t;
587588

588589
<a name="support"></a>

aws_iot_mqtt_client.py

100755100644
File mode changed.

certs/PlaceYourCertsHere

Whitespace-only changes.

0 commit comments

Comments
 (0)