Janosch-Kalich / RaspIO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RaspIO


General


  • When using the (Web)App, inputs, both from the Raspberry Pi and the Arduino, are sent through a websocket connection.

  • Additional / New Arduino code is required to allow special functionality e.g. Displays, Sensors or Motors


Endpoint Request body Response
/ {} { pins: { ... }, websockets: { ... } }

Raspberry Pi API


Usable Pins (physical):

3, 5, 7, 8, 10, 11,12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 35, 36, 37, 38, 40

pins.json:

{
    "pins": {
        "[id]":{
            "name": "String",
            "pin": "Number",
            "desc": "String",
            "type": "String (in/out)",
            "default": "Number (0/1)"
        }
    }
}

Raspberry Pi API Endpoints

Endpoint Request body Response
/addpin { name: ..., pin: ... , desc: ..., type: ..., default: ...} { id: ... }
/setpin { id: ..., props: { [property]: ..." } } { name: ..., pin: ... , desc: ..., type: ..., default: ...}
/deletepin { id: ... } { pins: { ... } }
/setpinstate { id: ..., state: ... } { name: ..., pin: ... , desc: ..., type: ..., default: ..., state: ... } or Nope
/getpin { id: ... } { name: ..., pin: ... , desc: ..., type: ..., default: ..., state: ... }

Datatypes as described in pins.json and:
state: Number (0/1)
property: String (Any Pin property)


Additional Information

  • When the program on the Raspberry Pi starts it will set every pin to it's specified default state.
  • The type attribute is mostly for UX and UI reasons, the Raspberry Pi can still /getpin for an output

Arduino API


As soon as the node.js program on the Raspberry Pi starts, it will try to connect to all saved Arduinos through websockets, if it fails to connect it will try to reconnect every 5 seconds 4 times, if it still isn't connected it has to be manually connected through /connectws.

websockets.json

{
    "websockets": {
        "[id/wsid]": {
            "name": "String",
            "desc": "String",
            "ip": "String",
            "hostname": "String",
            "port": "String",
            "pref": "String (IP / Hostname)",
            "input": {
                "[inputid]": {
                    "name": "String",
                    "type": "String"
                }
            },
            "output": {
                "[outputid]": {
                    "name": "String",
                    "data": {
                        "type": "Number (1-4)",
                        "id": "Number as String",
                        "value": "String"
                    }
                }
            }
        }
    }
}

App to Rasperry PI API

Endpoint Request body Response
/scan {} [{ name: ..., ip: ..., mac: ... }]
/testws { hostname: ..., ip: ..., port: ... } { msg: ..., method: ... } or { error: ... }
/connectws { id: ... } {}
/addws { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... } } { id: ... }
/getws { id: ... } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... },"output": { ... } }
/setws { id: ..., props: { [property]: ... } } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... } }
/deletews { id: ... } { websockets: { ... } }
/setwsinput { wsid: ..., inputid: ..., props: { [property]: ... } } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... } }
/deletewsinput { wsid: ..., inputid: ... } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... }}
/addwsoutput { wsid: ... } { id: ..., data: { name: ..., data: { type: 0, id: 0, value: false } } }
/setwsoutput { wsid: ..., outputid: ... } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... }}
/deletewsoutput { wsid: ..., outputid: ... } { name: ..., desc: ..., ip: ..., hostname: ..., port: ..., pref: ..., input: { ... }, output: { ... }}
/executewsoutput { id: ..., data: { type: ..., id: ..., value: ... } } {}

Datatypes as described in websockets.json and:
error: String
ip: String
name: String
mac: String
hostname: String
data.type: Number
data.id: Number
data.value: String


Additional Information

  • Inputs are declared by the Arduino when sending the value, (Web)App Clients don't need to refresh the page after a new input is added.

  • /scan scans from the Raspberry Pi, because of this some devices may be missing if connected to different Reapeaters, Switches or Hubs

  • /testws sends the first response it gets from the Arduino and will most likely look like 13:0.

  • /executewsoutput data gets sent as it is on the client but still through the Raspberry Pi to prevent sending newer, not yet updated, information. When directly interacting with the API, not through the (Web)App, data types should match with the required ones to prevent crashes of the Arduino software. Additionally, when directly interacting with the API, it is possible to use custom properties

  • /connectws closes the previous connection to prevent multiple connections to the same Arduino


Raspberry Pi to Arduino API


The Raspberry Pi sends data to the Arduino through websocket connections in JSON format ({ type: ..., id: ..., value: ... }) but receives information in id:value format. When type = 3 there is no value parameter.

All usable pins for type 0, 1, 4 have to be declared in the usablepins array in the json.h.

To use type, 2 and 3 and variables and functions need to be added to the corresponding arrays




PINS MUST BE IN PHYSICAL FORMAT

WeMos D1 Mini:




WeMos D1 R1:

About


Languages

Language:TypeScript 53.3%Language:HTML 29.3%Language:SCSS 14.0%Language:JavaScript 3.3%