ibbq-websocket

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-iBBQ Example WebSocket Server

Screenshot

Building

Linux
$ GOOS=linux go build
Linux (Raspberry Pi, etc.)
$ GOOS=linux GOARCH=arm go build
OS X
$ GOOS=darwin go build

Usage

In one shell:

$ LOGXI=main=INF ./ibbq-websocket
02:54:42.923948 INF main Starting websocket server port: 8080

In another shell:

$ curl --include \
    --no-buffer \
    --header "Connection: Upgrade" \
    --header "Upgrade: websocket" \
    --header "Host: localhost:8080" \
    --header "Origin: http://localhost:8080" \
    --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
    --header "Sec-WebSocket-Version: 13" \
    http://localhost:8080/ws
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk=

?${"batteryLevel":93,"temps":[21,21]}
?${"batteryLevel":93,"temps":[21,21]}
?${"batteryLevel":93,"temps":[21,21]}
?${"batteryLevel":93,"temps":[21,21]}
?${"batteryLevel":93,"temps":[21,20]}
?${"batteryLevel":93,"temps":[21,21]}
...

Install as a service on Raspberry Pi

(tested successfully on Raspbian 9)

Create the user and the install directory

(this only needs to be done the first time you install)

# useradd --comment 'ibbq websocket server user' --system --shell /usr/sbin/nologin ibbq
# mkdir -p /opt/ibbq-websocket
# chown -R ibbq:ibbq /opt/ibbq-websocket
Setup configuration and Systemd service

(this only needs to be done the first time you install)

In /opt/ibbq-websocket/ibbq-websocket.toml:

port = 80

In /etc/systemd/system/ibbq-websocket.service:

[Unit]
Description=iBBQ Websocket Server
After=network.target

[Service]
Type=simple
User=ibbq
WorkingDirectory=/opt/ibbq-websocket
Environment="LOGXI=main=INF"
ExecStart=/opt/ibbq-websocket/ibbq-websocket
Restart=on-failure
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN CAP_NET_RAW

[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl disable bluetooth.service
# systemctl stop bluetooth.service
# systemctl enable ibbq-websocket.service
Install the binary and configure permissions
# cp ibbq-websocket /opt/ibbq-websocket/ibbq-websocket
# chown -R ibbq:ibbq /opt/ibbq-websocket
Start the service
# systemctl start ibbq-websocket.service

Documentation

Overview

Copyright 2018 the original author or authors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL