Skip to content

Commit 219ce42

Browse files
aws-greengrass-sdk-lite: upgrade 0.2.0 -> 0.3.0
1 parent acf8fe8 commit 219ce42

File tree

4 files changed

+166
-149
lines changed

4 files changed

+166
-149
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//! Sample component demonstrating pubsub with AWS IoT Core using SDK Lite
2+
3+
#include <ggl/buffer.h>
4+
#include <ggl/error.h>
5+
#include <ggl/ipc/client.h>
6+
#include <ggl/sdk.h>
7+
#include <unistd.h>
8+
#include <stdbool.h>
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <time.h>
12+
#include <string.h>
13+
14+
static int message_counter = 0;
15+
static int successful_publishes = 0;
16+
static int failed_publishes = 0;
17+
18+
static void get_timestamp(char *buffer, size_t size) {
19+
time_t now = time(NULL);
20+
struct tm *tm_info = gmtime(&now);
21+
strftime(buffer, size, "%Y-%m-%dT%H:%M:%S.000Z", tm_info);
22+
}
23+
24+
static void response_handler(void *ctx, GglBuffer topic, GglBuffer payload, GgIpcSubscriptionHandle handle) {
25+
(void) ctx;
26+
(void) handle;
27+
char timestamp[32];
28+
get_timestamp(timestamp, sizeof(timestamp));
29+
30+
printf("[%s] [HelloWorldSDKLite] RECEIVED MESSAGE:\n", timestamp);
31+
printf(" Topic: [%.*s]\n", (int) topic.len, topic.data);
32+
printf(" Payload: [%.*s]\n", (int) payload.len, payload.data);
33+
printf(" Message Length: %zu bytes\n", payload.len);
34+
fflush(stdout);
35+
}
36+
37+
static void log_publish_success(const char* topic, const char* message) {
38+
char timestamp[32];
39+
get_timestamp(timestamp, sizeof(timestamp));
40+
41+
successful_publishes++;
42+
43+
printf("[%s] [HelloWorldSDKLite] PUBLISH SUCCESS #%d:\n", timestamp, successful_publishes);
44+
printf(" Topic: %s\n", topic);
45+
printf(" Message: %s\n", message);
46+
printf(" Total Successful: %d\n", successful_publishes);
47+
printf(" Total Failed: %d\n", failed_publishes);
48+
printf(" Success Rate: %.1f%%\n",
49+
(successful_publishes * 100.0) / (successful_publishes + failed_publishes));
50+
printf(" ----------------------------------------\n");
51+
fflush(stdout);
52+
}
53+
54+
static void log_publish_failure(const char* topic, const char* message, GglError error) {
55+
char timestamp[32];
56+
get_timestamp(timestamp, sizeof(timestamp));
57+
58+
failed_publishes++;
59+
60+
printf("[%s] [HelloWorldSDKLite] PUBLISH FAILED #%d:\n", timestamp, failed_publishes);
61+
printf(" Topic: %s\n", topic);
62+
printf(" Message: %s\n", message);
63+
printf(" Error Code: %d\n", error);
64+
printf(" Total Successful: %d\n", successful_publishes);
65+
printf(" Total Failed: %d\n", failed_publishes);
66+
if (successful_publishes + failed_publishes > 0) {
67+
printf(" Success Rate: %.1f%%\n",
68+
(successful_publishes * 100.0) / (successful_publishes + failed_publishes));
69+
}
70+
printf(" ----------------------------------------\n");
71+
fflush(stdout);
72+
}
73+
74+
int main(void) {
75+
char timestamp[32];
76+
get_timestamp(timestamp, sizeof(timestamp));
77+
78+
setvbuf(stdout, NULL, _IONBF, 0);
79+
80+
printf("[%s] [HelloWorldSDKLite] COMPONENT STARTING\n", timestamp);
81+
printf(" Component: com.example.HelloWorldSDKLite\n");
82+
printf(" Version: 1.0.0\n");
83+
printf(" Binary: hello-world-sdk-lite\n");
84+
printf(" ========================================\n");
85+
fflush(stdout);
86+
87+
ggl_sdk_init();
88+
89+
GglError ret = ggipc_connect();
90+
if (ret != GGL_ERR_OK) {
91+
get_timestamp(timestamp, sizeof(timestamp));
92+
printf("[%s] [HelloWorldSDKLite] FATAL: Failed to connect to GG nucleus (error: %d)\n", timestamp, ret);
93+
fflush(stderr);
94+
exit(1);
95+
}
96+
97+
get_timestamp(timestamp, sizeof(timestamp));
98+
printf("[%s] [HelloWorldSDKLite] Connected to GG nucleus successfully\n", timestamp);
99+
fflush(stdout);
100+
101+
GgIpcSubscriptionHandle sub_handle;
102+
ret = ggipc_subscribe_to_iot_core(GGL_STR("hello"), 0, &response_handler, NULL, &sub_handle);
103+
if (ret != GGL_ERR_OK) {
104+
get_timestamp(timestamp, sizeof(timestamp));
105+
printf("[%s] [HelloWorldSDKLite] WARNING: Failed to subscribe to IoT Core topic 'hello' (error: %d)\n", timestamp, ret);
106+
printf(" Continuing with publish-only mode...\n");
107+
fflush(stdout);
108+
} else {
109+
get_timestamp(timestamp, sizeof(timestamp));
110+
printf("[%s] [HelloWorldSDKLite] Successfully subscribed to IoT Core topic 'hello'\n", timestamp);
111+
fflush(stdout);
112+
}
113+
114+
get_timestamp(timestamp, sizeof(timestamp));
115+
printf("[%s] [HelloWorldSDKLite] Starting publish loop (15 second intervals)\n", timestamp);
116+
fflush(stdout);
117+
118+
while (true) {
119+
message_counter++;
120+
121+
// Create detailed message with metadata
122+
char message[512];
123+
get_timestamp(timestamp, sizeof(timestamp));
124+
snprintf(message, sizeof(message),
125+
"{"
126+
"\"message\":\"Hello from Greengrass SDK Lite!\","
127+
"\"component\":\"com.example.HelloWorldSDKLite\","
128+
"\"version\":\"1.0.0\","
129+
"\"counter\":%d,"
130+
"\"timestamp\": \"%s\","
131+
"\"successful_publishes\":%d,"
132+
"\"failed_publishes\":%d"
133+
"}",
134+
message_counter, timestamp, successful_publishes, failed_publishes);
135+
136+
ret = ggipc_publish_to_iot_core(GGL_STR("hello"), (GglBuffer){.data = (uint8_t*)message, .len = strlen(message)}, 0);
137+
if (ret != GGL_ERR_OK) {
138+
log_publish_failure("hello", message, ret);
139+
} else {
140+
log_publish_success("hello", message);
141+
}
142+
143+
// Log periodic statistics
144+
if (message_counter % 10 == 0) {
145+
get_timestamp(timestamp, sizeof(timestamp));
146+
printf("[%s] [HelloWorldSDKLite] PERIODIC STATS:\n", timestamp);
147+
printf(" Messages Sent: %d\n", message_counter);
148+
printf(" Successful Publishes: %d\n", successful_publishes);
149+
printf(" Failed Publishes: %d\n", failed_publishes);
150+
if (message_counter > 0) {
151+
printf(" Overall Success Rate: %.1f%%\n",
152+
(successful_publishes * 100.0) / message_counter);
153+
}
154+
printf(" ========================================\n");
155+
fflush(stdout);
156+
}
157+
158+
sleep(15);
159+
}
160+
}

recipes-sdk/aws-greengrass-sdk-lite/aws-greengrass-sdk-lite/0001-fix-crc32-syntax.patch

Lines changed: 0 additions & 26 deletions
This file was deleted.

recipes-sdk/aws-greengrass-sdk-lite/aws-greengrass-sdk-lite/0002-build-both-static-and-shared.patch

Lines changed: 0 additions & 115 deletions
This file was deleted.

recipes-sdk/aws-greengrass-sdk-lite/aws-greengrass-sdk-lite_0.2.0.bb renamed to recipes-sdk/aws-greengrass-sdk-lite/aws-greengrass-sdk-lite_0.3.0.bb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ HOMEPAGE = "https://github.com/aws-greengrass/aws-greengrass-sdk-lite"
66
LICENSE = "Apache-2.0"
77
LIC_FILES_CHKSUM = "file://LICENSE;md5=34400b68072d710fecd0a2940a0d1658"
88

9-
SRCREV = "0835c6ad20948ab55d86fbd5864fd38e62559ed2"
9+
SRCREV = "1ee3a5ad3de59f141973839412b5025e67ea533d"
1010
SRC_URI = "git://github.com/aws-greengrass/aws-greengrass-sdk-lite.git;protocol=https;branch=main \
11-
file://0001-fix-crc32-syntax.patch \
12-
file://0002-build-both-static-and-shared.patch \
1311
"
1412

1513
S = "${WORKDIR}/git"
@@ -80,10 +78,10 @@ do_install() {
8078
do_compile_ptest() {
8179
# Compile test programs using shared library
8280
${CC} ${CFLAGS} ${LDFLAGS} -I${S}/include -I${S}/priv_include \
83-
-o ${B}/test-basic-api ${WORKDIR}/test-basic-api.c -L${B} -lggl-sdk -lpthread
81+
-o ${B}/test-basic-api ${WORKDIR}/test-basic-api.c -L${B}/lib -lggl-sdk -lpthread
8482

8583
${CC} ${CFLAGS} ${LDFLAGS} -I${S}/include -I${S}/priv_include \
86-
-o ${B}/test-json-ops ${WORKDIR}/test-json-ops.c -L${B} -lggl-sdk -lpthread
84+
-o ${B}/test-json-ops ${WORKDIR}/test-json-ops.c -L${B}/lib -lggl-sdk -lpthread
8785
}
8886

8987
do_install_ptest() {
@@ -103,19 +101,19 @@ PACKAGES = "${PN} ${PN}-dev ${PN}-staticdev ${PN}-doc ${PN}-ptest ${PN}-ptest-db
103101

104102
# Main package contains shared library and sample binaries if enabled
105103
FILES:${PN} = " \
106-
${libdir}/libggl-sdk.so.* \
104+
${libdir}/libggl-sdk.so* \
107105
${@bb.utils.contains('PACKAGECONFIG', 'samples', '${bindir}/*', '', d)} \
108106
"
109107

110-
# Development package contains headers and shared library symlinks
108+
# Development package contains headers
111109
FILES:${PN}-dev = " \
112110
${includedir}/ggl/* \
113-
${libdir}/libggl-sdk.so \
114111
"
115112

116113
# Static development package contains static library
117114
FILES:${PN}-staticdev = " \
118115
${libdir}/libggl-sdk.a \
116+
${libdir}/libggl-sdk++.a \
119117
"
120118

121119
# Documentation package

0 commit comments

Comments
 (0)