GithubHelp home page GithubHelp logo

pisugar / sugar-wifi-conf Goto Github PK

View Code? Open in Web Editor NEW
125.0 13.0 44.0 29.24 MB

A BLE service on raspberry pi for wifi configuration and wireless control. 使用微信小程序随时随地设置树莓派wifi连接,控制树莓派

License: GNU General Public License v3.0

JavaScript 83.39% Shell 0.88% HTML 0.27% Vue 15.47%
raspberry pi wechat miniapp bluetooth ble weixin bluetooth-low-energy wifi rpi

sugar-wifi-conf's Introduction

sugar-wifi-conf

PiSugar Wechat MiniApp

English | 简体中文

A BLE service to configure wifi over bluetooth for a Raspberry Pi. You can:

  • get wifi name, ip address, pi model
  • config wifi
  • get other custom info, e.g. CPU tempreture, CPU load, or whatever you can get by shell
  • remote control the pi to execute shell script and get response, such as shutdown, reboot

Tested on Raspberry Pi 3B/3B+/zero w (models with bluetooth) with Raspbian.

To access client-side app, please use Wechat app to scan the QR-code above. Source code of client-side is in folder /sugar-wifi-miniapp.

If you don't have wechat, you can use web-bluetooth to connect to your pi. Make sure your device and broswer support web-bluetooth api, visit https://www.pisugar.com/sugar-wifi-conf to connect. (Tested on MacOS and Android with Chrome, iOS WebBLE browser) Source code of web-bluetooth client is in folder /web-bluetooth-client.

Quick Install

wget http://cdn.pisugar.com/release/sugarwificonfig.sh -O- | sh

Install from Github

git clone https://github.com/PiSugar/sugar-wifi-conf.git
sudo -s . ./sugar-wifi-conf/wificonfig.sh

# the scrpit will add sugar-wifi-conf to /etc/rc.local so that it can run on startup

## optional parameters

# edit /etc/rc.local to append parameters to execute path 
# param 1: key 
# param 2: path to custom config file
# example: 
sudo /home/pi/sugar-wifi-conf/build/sugar-wifi-conf pisugar /home/pi/sugar-wifi-conf/custom_config.json

Custom configuration

By editing the custom config file, you can let the pi broadcast custom data, recieve and execute custom shell scripts. Note: please ensure that the config file is accessable for the program.

custom_config.json example

{
  "note": {
    "info" : {
      "label": "name of the item, within 20 bytes",
      "command": "the command to get value of the item, within 20 bytes",
      "interval": "run command to get data in every X seconds"
    },
   "commands": {
      "label": "name of the item, within 20 bytes",
      "command": "the command to execute"
    }
  },
  "info": [
    {
      "label": "CPU Temp",
      "command": "vcgencmd measure_temp | cut -d = -f 2 | awk '{printf \"%s \", $1}'",
      "interval": 5
    },
    {
      "label": "CPU Load",
      "command": "top -bn1 | grep load | awk '{printf \"%.2f%%\", $(NF-2)}'",
      "interval": 1
    },
    {
      "label": "Memory",
      "command": "free -m | awk 'NR==2{printf \"%s/%sMB\", $3,$2 }'",
      "interval": 5
    },
    {
      "label": "UP Time",
      "command": "uptime -p | cut -d 'p' -f 2 | awk '{ printf \"%s\", $0 }'",
      "interval": 10
    }
  ],
  "commands": [
    {
      "label": "ls",
      "command": "ls"
    },
    {
      "label": "shutdown",
      "command": "shutdown"
    },
    {
      "label": "cancel shutdown",
      "command": "shutdown -c"
    },
    {
      "label": "reboot",
      "command": "reboot"
    }
  ]
}

BLE datasheet

You can build your own client-side app base on this datasheet.

Service uuid: FD2B-4448-AA0F-4A15-A62F-EB0BE77A0000

charateristic uuid properties note
SERVICE_NAME FD2B-4448-AA0F-4A15-A62F-EB0BE77A0001 read service name
DEVICE_MODEL FD2B-4448-AA0F-4A15-A62F-EB0BE77A0002 read pi model info
WIFI_NAME FD2B-4448-AA0F-4A15-A62F-EB0BE77A0003 notify current wifi name
IP_ADDRESS FD2B-4448-AA0F-4A15-A62F-EB0BE77A0004 notify internal ip addresses
INPUT FD2B-4448-AA0F-4A15-A62F-EB0BE77A0005 write input for configuring wifi (deprecated)
NOTIFY_MESSAGE FD2B-4448-AA0F-4A15-A62F-EB0BE77A0006 notify response for configuring wifi
INPUT_SEP FD2B-4448-AA0F-4A15-A62F-EB0BE77A0007 write input for configuring wifi(subcontracting)
CUSTOM_COMMAND_INPUT FD2B-4448-AA0F-4A15-A62F-EB0BE77A0008 write input for custom commands(subcontracting)
CUSTOM_COMMAND_NOTIFY FD2B-4448-AA0F-4A15-A62F-EB0BE77A0009 notify response for custom commands(subcontracting)
CUSTOM_INFO_LABEL 0000-0000-0000-0000-0000-FD2BCCCAXXXX read label of custom info
CUSTOM_INFO 0000-0000-0000-0000-0000-FD2BCCCBXXXX notify value of custom info
CUSTOM_COMMAND_LABEL 0000-0000-0000-0000-0000-FD2BCCCCXXXX read label of custom command

Input and Output format

charateristic format
INPUT_SEP format: key%&%ssid%&%password&#& (subcontract in 20 btyes) e.g. pisugar%&%home_wifi%&%12345678&#&
CUSTOM_COMMAND_INPUT format: key%&%last_4_digit_uuid&#& (subcontract in 20 btyes) e.g. pisugar%&%1234&#& will execute the custom command with its label uuid end in "1234"
CUSTOM_COMMAND_NOTIFY subcontract in 20 btyes, ended in "&#&"
CUSTOM_INFO_LABEL a custom info label (FD2BCCCA1234) will have a corresponding value (FD2BCCCB1234)
CUSTOM_COMMAND_LABEL all custom commands with be broadcast in uuid "FD2BCCCCXXXX"

sugar-wifi-conf's People

Contributors

dependabot[bot] avatar jdaielin avatar wlmh110 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sugar-wifi-conf's Issues

npm run dev fails.

Whenever I try to run in the "web-bluetooth-client" directory:
npm run dev

I get the following error:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Any ideas on how to fix this?

Security vulnerability

WS-2019-0063 More information

high severity
Vulnerable versions: < 3.13.1
Patched version: 3.13.1

WS-2019-0032 More information

moderate severity
Vulnerable versions: < 3.13.0
Patched version: 3.13.0

config file is not accessed

HI!
I added this line: sudo /home/pi/sugar-wifi-conf/build/sugar-wifi-conf pisugar /home/pi/sugar-wifi-conf/custom_config.json in rc.local file but on client side nothing changed

Error after npm run dev in web-bluetooth-client

Log file:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/usr/local/Cellar/node/12.10.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'dev'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle [email protected]predev: [email protected]
6 info lifecycle [email protected]
dev: [email protected]
7 verbose lifecycle [email protected]dev: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]
dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/$
9 verbose lifecycle [email protected]dev: CWD: /Users/Arahasya/blue-pi/web-bluetooth-client
10 silly lifecycle [email protected]
dev: Args: [
10 silly lifecycle '-c',
10 silly lifecycle 'webpack-dev-server --inline --progress --config build/webpack.dev.conf.js'
10 silly lifecycle ]
11 silly lifecycle [email protected]dev: Returned: code: 1 signal: null
12 info lifecycle [email protected]
dev: Failed to exec dev script
13 verbose stack Error: [email protected] dev: webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:209:13)
13 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:209:13)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/Arahasya/blue-pi/web-bluetooth-client
16 verbose Darwin 18.7.0
17 verbose argv "/usr/local/Cellar/node/12.10.0/bin/node" "/usr/local/bin/npm" "run" "dev"
18 verbose node v12.10.0
19 verbose npm v6.11.3
20 error code ELIFECYCLE
21 error errno 1

DOMException: No Services found in device.

Hi !

First, thanks for this great project.

While the page is working perfectly on Chrome Desktop (ubuntu), I'm having trouble making the web page work on Chrome Android:

It seems to fail when calling server.getPrimaryService(UUID.SERVICE_ID):

DOMException: No Services matching UUID fd2b4448-aa0f-4a15-a62f-eb0be77a0000 found in Device.

I have also tried to server.getPrimaryServices() instead, but it says:

DOMException: No Services found in device.

I have looked into chrome://bluetooth-internals, and indeed the service is not visible, despite the 'raspberrypi' device displaying in the list of devices when clicking on "Discover" (which seems to imply the service is advertised)

Services visible on Desktop:

  • fd2b4448-aa0f-4a15-a62f-eb0be77a0000 <= the expected service, contains almost about 20 characteristics
  • 00001801-0000-1000-8000-00805f9b34fb

Services visible on Mobile:

  • 00001801-0000-1000-8000-00805f9b34fb <= also visible from desktop
  • 00001800-0000-1000-8000-00805f9b34fb <= not visible on desktop, but has no characteristics

Chrome versions:

  • Mobile: 91.0.4472.120 (Android 10)
  • Desktop: 90.0.4430.212 (Official Build) (64-bit)

I have no real idea what I can do, all I know is I'd really love to make it work on my phone 😅

Please note the device is a Raspberry pi Zero (system completely up-to-date from today)

Anyway, thanks for the great work !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.