-
Notifications
You must be signed in to change notification settings - Fork 40
/
WebServerNode.js
42 lines (31 loc) · 1.24 KB
/
WebServerNode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// WebServerNode.js
const ggSdk = require('greengrass-core-sdk')
const iotClient = new ggSdk.IotData()
const os = require('os')
const express = require('express')
const GROUP_ID = process.env.GROUP_ID
const THING_NAME = process.env.AWS_IOT_THING_NAME
const THING_ARN = process.env.AWS_IOT_THING_ARN
const PORT = process.env.PORT
const base_topic = THING_NAME + '/web_server_node'
const log_topic = base_topic + '/log'
function publishCallback(err, data) {
console.log(err);
console.log(data);
}
// This is a handler which does nothing for this example
exports.function_handler = function(event, context) {
console.log('event: ' + JSON.stringify(event));
console.log('context: ' + JSON.stringify(context));
};
const app = express()
app.get('/', (req, res) => {
res.send('Hello World!')
const pubOpt = {
topic: log_topic,
payload: JSON.stringify({ message: 'Hello World request serviced' })
};
iotClient.publish(pubOpt, publishCallback);
}
)
app.listen(PORT, () => console.log('Example app listening on port ${PORT}!'))