Skip to content

Commit

Permalink
Fixes for 12.0 PJON version, changes for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleh L. Halytskyi committed Jan 9, 2020
1 parent e6e93a3 commit 16b7f6f
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 133 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# PJON-gRPC
PJON-gRPC is a server-client interface for linux-based machines (scripts can be written on [different languages](https://grpc.io/docs/)) and devices Arduino, ATtiny, ATmega, ESP8266, etc.

### Components
PJON-gRPC is a server-client interface for linux-based machines (applications can be written on [different languages](https://grpc.io/docs/)) and devices Arduino, ATtiny, ATmega, ESP8266, etc.

## Components

**PJON™** (Padded Jittering Operative Network) is an Arduino compatible, multi-master, multi-media communications bus system created and mantained by Giovanni Blu Mitolo gioscarab@gmail.com https://github.com/gioblu/PJON

**gRPC** is a modern open source high performance RPC framework that can run in any environment https://github.com/grpc/grpc

### Server features
## Server features

- Receive requests from application located on RPi/PC (via gRPC, for example [pjon_grpc_client.py](examples/clients/python/pjon_grpc_client.py)) and send back responses from devices (like Arduino) connected with RPi through PJON [ThroughSerialAsync](https://github.com/gioblu/PJON/tree/master/src/strategies/ThroughSerialAsync) strategy.
- Receive and forward messages to application located on RPi/PC from devices through PJON [ThroughSerialAsync](https://github.com/gioblu/PJON/tree/master/src/strategies/ThroughSerialAsync) strategy (via gRPC, for example [pjon_grpc_clientserver.py](examples/clients/python/pjon_grpc_clientserver.py))
- Communication between RPi/PC and devices (like Arduino) through any [PJON strategies](https://github.com/gioblu/PJON/blob/master/documentation/configuration.md) via [router](examples/devices/router_extender)
- Can be configured for working with 2 modules at the same time (see [pjon-grpc.cfg](server/conf/pjon-grpc.cfg)). Logic isolated in separate threads for maximum performance. Very useful if need to distribute the load, for example, `1st module` can be configured for accept and response on requests, `2nd module` can be configured for accept only incoming messages.

**Required** PJON version >[11.1](https://github.com/gioblu/PJON/tree/11.1)
## Tested with

**PJON version:** [12.0](https://github.com/gioblu/PJON/tree/12.0)<br>
**Device:** [Raspberry Pi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/)<br>
**OS:** [Raspbian buster](https://www.raspberrypi.org/downloads/raspbian/)

**Tested** and fully compatible with [master branch](https://github.com/gioblu/PJON/tree/master)
## Video example (for old version, will be changed)

#### Video example
https://www.youtube.com/watch?v=J8FVPZW4y4I
6 changes: 4 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**clients** - examples of applications which running on RPi/PC side
# Examples

**devices** - examples of Arduino sketches
[clients](clients) - examples of applications which running on RPi/PC side

[devices](devices) - examples of Arduino sketches
49 changes: 31 additions & 18 deletions examples/clients/python/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
### Install gRPC and gRPC tools:
```
$ virtualenv .venv
$ source .venv/bin/activate
$ python -m pip install --upgrade pip
$ python -m pip install grpcio
$ python -m pip install grpcio-tools
```
# Client python tools

## Install gRPC and gRPC tools

### Generate gRPC code:
```bash
apt-get install python3 python3-dev python3-venv -y
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install grpcio
python -m pip install grpcio-tools
```
$ ./run_codegen.py

### Generate gRPC code

```bash
./run_codegen.py
```

OR
```
$ python -m grpc_tools.protoc -Iprotos --python_out=. --grpc_python_out=. protos/pjongrpc.proto
```

### Examples of run
**pjon_grpc_client.py** - client for sending requests to devices and getting responses
```bash
python -m grpc_tools.protoc -Iprotos --python_out=. --grpc_python_out=. protos/pjongrpc.proto
```

## Examples of run

[pjon_grpc_client.py](pjon_grpc_client.py) - client for sending requests to devices and getting responses

```bash
$ ./pjon_grpc_client.py 1 11 n
Client received: n>1
```

where:
```

```bash
1 - master ID
11 - device ID
n - command
```
**pjon_grpc_clientserver.py** - client-server script for receiving messages from devices (works in daemon mode)
```

[pjon_grpc_clientserver.py](pjon_grpc_clientserver.py) - client-server script for receiving messages from devices (works in daemon mode)

```bash
$ ./pjon_grpc_clientserver.py
Client-Server received: node_id=11, data=29
```
34 changes: 19 additions & 15 deletions examples/devices/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
### Arduino examples
# Arduino devices

#### Makefile
## Makefile

If you want compiling code and flashing it to Arduino directly from RPi need install/configure [Arduino-Makefile](https://github.com/sudar/Arduino-Makefile).

Install necessary packages
```
$ sudo apt-get install python-serial git
```

Download [Arduino IDE 1.6.13](https://www.arduino.cc/en/Main/OldSoftwareReleases#previous) to `/opt` and:
```bash
apt-get install python-serial git -y
```
$ cd /opt
$ tar xf arduino-1.6.13-linuxarm.tar.xz && rm -rf arduino-1.6.13-linuxarm.tar.xz
$ ln -s arduino-1.6.13 arduino
$ cd arduino
$ git clone https://github.com/sudar/Arduino-Makefile.git
$ cd Arduino-Makefile && git checkout 1.6.0

Download [Arduino IDE 1.8.10](https://www.arduino.cc/en/Main/OldSoftwareReleases#previous) to `/opt` and run commands

```bash
cd /opt
tar xf arduino-1.8.10-linuxarm.tar.xz
rm -rf arduino-1.8.10-linuxarm.tar.xz
ln -s arduino-1.8.10 arduino
cd /opt
git clone https://github.com/sudar/Arduino-Makefile.git
cd Arduino-Makefile && git checkout 1.6.0
```

Add PJON library to Arduino IDE (assume that you downloaded it to `/opt/libraries/PJON`):
```
$ cd /opt/arduino/libraries
$ ln -s /opt/libraries/PJON

```bash
cd /opt/arduino/libraries
ln -s /opt/libraries/PJON
```
4 changes: 2 additions & 2 deletions examples/devices/direct_connect/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ BOARD_SUB = atmega328
MONITOR_PORT = /dev/ttyUSB0
CXXFLAGS_STD = -std=c++11
AVR_TOOLS_DIR = /opt/arduino/hardware/tools/avr
ARDMK_DIR = /opt/arduino/Arduino-Makefile
ARDMK_DIR = /opt/Arduino-Makefile
ARDUINO_DIR = /opt/arduino
AVRDUDE = /opt/arduino/hardware/tools/avr/bin/avrdude
AVRDUDE_CONF = /opt/arduino/hardware/tools/avr/etc/avrdude.conf
include /opt/arduino/Arduino-Makefile/Arduino.mk
include /opt/Arduino-Makefile/Arduino.mk
52 changes: 37 additions & 15 deletions examples/devices/direct_connect/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,86 @@
# Direct connect

This example show how possible control Arduino PINs or send messages to RPi/PC via PJON-gRPC tool.

Arduino connected directly to RPi through serial (USB).

### Examples
**Note:** use python client '[pjon_grpc_client.py](../../clients/python/pjon_grpc_client.py)' on RPi/PC side
## Examples

**Note:** from RPi/PC side uses python client: [pjon_grpc_client.py](../../clients/python/pjon_grpc_client.py)

#### Examples "request -> response"
### Examples of request -> response (RPi/PC -> Arduino)

Read Hardware Digital PIN (_digitalRead(13)_):
```

```bash
$ ./pjon_grpc_client.py 1 21 H-13
Client received: H-13>0
```

Read Hardware Analog PIN (_analogRead(14)_):
```

```bash
$ ./pjon_grpc_client.py 1 21 H-14
Client received: H-14>275
```

Write Hardware Digital PIN (_digitalWrite(13, 1)_):
```

```bash
$ ./pjon_grpc_client.py 1 21 H-13-1
Client received: H-13-1>1
```

Read Virtual PIN:
```

```bash
$ ./pjon_grpc_client.py 1 21 V-0
Client received: V-0>0
```

Write Virtual PIN:
```

```bash
$ ./pjon_grpc_client.py 1 21 V-0-1
Client received: V-0-1>1
```

Read again the same PIN (after write):
```

```bash
$ ./pjon_grpc_client.py 1 21 V-0
Client received: V-0>1
```

Make test, number in response will be increased on 1:
```

```bash
$ for i in $(seq 1 2); do ./pjon_grpc_client.py 1 21 N; done
Client received: N>1
Client received: N>2
```

Wrong command:
```

```bash
$ ./pjon_grpc_client.py 1 21 T
Client received: T>wrong command
```

#### Example of sending messages 'Arduino -> RPi/PC'
**Note:** Use '[pjon_grpc_clientserver.py](../../clients/python/pjon_grpc_clientserver.py)' for receiving messages on RPi/PC side
### Example of sending messages (Arduino -> RPi/PC)

**Note:** from RPi/PC side for receiving messages uses python script: [pjon_grpc_clientserver.py](../../clients/python/pjon_grpc_clientserver.py)

Enable sending messages every 1 second from Arduino to RPi/PC:
```

```bash
$ ./pjon_grpc_client.py 1 21 M-1
Client received: M-1>1
```

On RPi/PC side we should see:
```

```bash
$ ./pjon_grpc_clientserver.py
Client-Server received: node_id=21, data=<Incoming message every 1 sec
Client-Server received: node_id=21, data=<Incoming message every 1 sec
Expand Down
14 changes: 9 additions & 5 deletions examples/devices/router_extender/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Router extenders

**router_extender** - communication between RPi and devices with different strategies
```cpp

```bash
RPi <—--ThroughSerialAsync---> Arduino (router) <—--SoftwareBitBang--—> Arduino (device1)
|
<---ThroughSerialAsync (HC-12)---> Arduino (device2)
|
<--- Other PJON strategy---> Arduino (deviceN)
```
**router_1_bus** - sketch for Arduino router which allow RPi communicate with devices connected to one PJON bus, see device example: [device1](device1)

**router_2_bus** - sketch for Arduino router which allow RPi communicate with devices connected to two different PJON bus, see device examples: [device1](device1) and [device2](device2)
[router_1_bus](router_1_bus) - sketch for Arduino router which allow RPi communicate with devices connected to one PJON bus, see device example: [device1](device1)

[router_2_bus](router_2_bus) - sketch for Arduino router which allow RPi communicate with devices connected to two different PJON buses, see device examples: [device1](device1) and [device2](device2)

**device1** - sketch for Arduino device which connected to Arduino router via [SoftwareBitBang](https://github.com/gioblu/PJON/tree/master/src/strategies/SoftwareBitBang) strategy
[device1](device1) - sketch for Arduino device which connected to Arduino router via [SoftwareBitBang](https://github.com/gioblu/PJON/tree/master/src/strategies/SoftwareBitBang) strategy

**device2** - sketch for Arduino device which connected to Arduino router via [ThroughSerialAsync](https://github.com/gioblu/PJON/tree/master/src/strategies/ThroughSerialAsync) strategy ([HC-12 module](http://statics3.seeedstudio.com/assets/file/bazaar/product/HC-12_english_datasheets.pdf))
[device2](device2) - sketch for Arduino device which connected to Arduino router via [ThroughSerialAsync](https://github.com/gioblu/PJON/tree/master/src/strategies/ThroughSerialAsync) strategy ([HC-12 module](http://statics3.seeedstudio.com/assets/file/bazaar/product/HC-12_english_datasheets.pdf))
4 changes: 2 additions & 2 deletions examples/devices/router_extender/device1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ BOARD_SUB = atmega328
MONITOR_PORT = /dev/ttyUSB1
CXXFLAGS_STD = -std=c++11
AVR_TOOLS_DIR = /opt/arduino/hardware/tools/avr
ARDMK_DIR = /opt/arduino/Arduino-Makefile
ARDMK_DIR = /opt/Arduino-Makefile
ARDUINO_DIR = /opt/arduino
AVRDUDE = /opt/arduino/hardware/tools/avr/bin/avrdude
AVRDUDE_CONF = /opt/arduino/hardware/tools/avr/etc/avrdude.conf
include /opt/arduino/Arduino-Makefile/Arduino.mk
include /opt/Arduino-Makefile/Arduino.mk
Loading

0 comments on commit 16b7f6f

Please sign in to comment.