Skip to content

Commit

Permalink
Add bus demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhitoyokoi committed Dec 30, 2022
1 parent 6ba1fb6 commit 4f3544b
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 4 deletions.
41 changes: 41 additions & 0 deletions docs/bus.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
</head>
<body>
<div id="map" style="width: 100%; height: 100%;"></div>
<script src="./wasm_exec.js"></script>
<script>
(async () => {
const go = new Go();
const { instance } = await WebAssembly.instantiateStreaming(
fetch('bus.wasm'),
go.importObject
);
await go.run(instance);
})();
async function run() {
console.clear();
await go.run(inst);
inst = await WebAssembly.instantiate()
}
</script>
<script>
var map = L.map('map');
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
map.setView([35.3386861, 139.4870951], 7);
alert("msgData1");
function debug(msgData) {
var msg = JSON.parse(msgData);
alert(msg);
//map.setView([msg.latitude, msg.longitude]);
//L.marker([msg.latitude, msg.longitude],{"color": "#910000"}).addTo(map);
for (var i = 0; i < msg.length; i++) {
//map.setView([msg.latitude, msg.longitude]);
L.marker([msg[i].stop_lat, msg[i].stop_lon],{"color": "#910000"}).addTo(map);
}
}
</script>
</body>
</html>
Binary file added docs/bus.wasm
Binary file not shown.
Binary file modified docs/console.wasm
100644 → 100755
Binary file not shown.
Binary file modified docs/worldmap.wasm
100644 → 100755
Binary file not shown.
71 changes: 71 additions & 0 deletions examples/bus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[
{
"id": "8740d4c87aa226d5",
"type": "http request",
"z": "506a7e799b8b8c67",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://kazuhitoyokoi.github.io/ogiri-bus-api/bus.json",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 390,
"y": 120,
"wires": [
[
"9ae96b81d3eb6fe2"
]
]
},
{
"id": "7d5ef118b8c6f3cb",
"type": "inject",
"z": "506a7e799b8b8c67",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 120,
"wires": [
[
"8740d4c87aa226d5"
]
]
},
{
"id": "9ae96b81d3eb6fe2",
"type": "debug",
"z": "506a7e799b8b8c67",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 120,
"wires": []
}
]
3 changes: 2 additions & 1 deletion flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func flows() string { return `
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.wheretheiss.at/v1/satellites/25544",
"url": "https://kazuhitoyokoi.github.io/ogiri-bus-api/bus.json",
"tls": "",
"persist": false,
"proxy": "",
Expand Down Expand Up @@ -71,4 +71,5 @@ func flows() string { return `
"wires": []
}
]
`}
5 changes: 3 additions & 2 deletions red.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func execute(nodeId string, msg string) {
json.Unmarshal([]byte(msg), &msgData)
var output = msgData.(map[string]interface{})["payload"]
var text = ""
if reflect.TypeOf(output).Kind() == reflect.Float64 {
var kind = reflect.TypeOf(output).Kind()
if kind == reflect.Float64 {
text = strconv.FormatFloat(output.(float64), 'f', -1, 64)
} else if reflect.TypeOf(output).Kind() == reflect.Map {
} else if kind == reflect.Map || kind == reflect.Slice {
jsonData, _ := json.Marshal(output)
text = string(jsonData)
} else {
Expand Down
6 changes: 5 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ GOOS=js GOARCH=wasm go build -o docs/console.wasm
node codegen.js ./examples/worldmap.json > flows.go
GOOS=js GOARCH=wasm go build -o docs/worldmap.wasm

node codegen.js ./examples/bus.json > flows.go
GOOS=js GOARCH=wasm go build -o docs/bus.wasm

#go run red.go flows.go
python3 -m http.server 8080 &
open http://localhost:8080/docs
#open http://localhost:8080/docs
open http://localhost:8080/docs/bus.htm

0 comments on commit 4f3544b

Please sign in to comment.