IP Switch with ESP32-GATEWAY

Difference between revisions from 2019/07/08 21:07 and 2019/07/08 21:07.
[<-- Order page|https://remoteqth.com/order.php#ip-sw-mk2]
[<-- Web|https://remoteqth.com/ip-switch-mk2.php]
[<-- Control box|Manual IP switch II]

Designed for mounting to DIN rail.
Board serve as '''relay driver''' depenancy to used [open collector/emmiter output chip.|https://remoteqth.com/wiki/index.php?page=IP+Switch+with+ESP32-GATEWAY#Output_driver] This kit worked with [ESP32-GATEWAY|https://www.olimex.com/Products/IoT/ESP32-GATEWAY/open-source-hardware] Ethernet/WiFi module from OLIMEX. Below step by step assembled manual for 16 outputs (two boards), may be expandable.  

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-01.jpg]
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-02.jpg]


!Hardware
* [Schematics|https://remoteqth.com/hw/ip-switch-with-esp32-gateway-02.pdf]
* [Firmware on GitHub|https://github.com/ok1hra/IP_switch]
* [PCB 3D view|https://remoteqth.com/x3d-preview.php?x3d=ip-switch-esp32gateway]
* [Interactive BOM|https://remoteqth.com/hw/ip-switch-esp32gateway-ibom.html]

!!DC power jack
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-17.png|noborder|right]
* '''{.redka#id color: #f23f37; font-size: 200%}⚠{/} {.redka#id color: #f23f37}5 volt DC only{/} - higher voltage damage both electronics!'''
* Size 2,1/5,5mm diameter to connect input power 5V DC (center positive) 
* Consumption below 500mA

!! P3 output header
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-18.png|noborder|right]
| pin-1 | in | DC power supply '''+5V''' |
| pin-2 | in | DC power supply '''+5V''' |
| pin-3 | in | '''GND''' |
| pin-4 | in | '''GND''' |
| pin-5 | out | output '''1''' |
| pin-6 | out | output '''2''' |
| pin-7 | out | output '''3''' |
| pin-8 | out | output '''4''' |
| pin-9 | out | output '''5''' |
| pin-10 | out | output '''6''' |
| pin-11 | out | output '''7''' |
| pin-12 | out | output '''8''' |
| pin-13 | in | '''Vin''', if use UDN driver |
| pin-14 | in | '''Vin''', if use UDN driver |


!How to assembly
!!Top side PCB
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-01.png|noborder]
❏ Solder '''2x12 1k rezistors''' R1-R14

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-02.png|noborder]
❏ '''2x10 100n''' capacitors C19-C35

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-03.png|noborder]
❏ '''2x8 LED''' diodes D38-D45

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-04.png|noborder]
❏ '''One BCD ID''' switch P6 on '''LEFT board'''

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-05.png|noborder]
❏ '''One female pin header''' P5 on '''LEFT board'''

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-06.png|noborder]
❏ '''One male pin header''' P4 on '''RIGHT board'''

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-07.png|noborder]
❏ '''2x 74HC595 IO''' U8

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-08.png|noborder]
❏ '''2x DIP socket''' for U5

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-09.png|noborder]
❏ '''2x male 2x3 pin header''' P2

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-10.png|noborder]
❏ '''2x male 2x7 pin header''' P3

!! Bottom side PCB
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-11.png|noborder]
❏ '''One DC jack''' J1 on '''LEFT board'''

[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-12.png|noborder]
❏ '''One male 1x20 pin header''' P1 on '''LEFT board'''
!!!Output driver
❏ '''Put output driver''' to DIP socket by your preferency
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-14.png|noborder]
* '''ULN''' chip for switching by output collector (grounding) need use two Jumpers on left P2 pin strip[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-15.png]
* '''UDN''' chip for switching by output emitter (voltage from P3 Vin) need use two Jumpers on right P2 pin strip[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-16.png]

!! ESP32-GATEWAY board
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-13.png|noborder]
❏ '''One femmale 1x20 pin header''' CON1 on TOP side '''OLIMEX ESP32-GATEWAY'''
!!!LED1 on ESP32-GATEWAY show
* '''three times flashes''' - receive IP from DHCP server - Ethernet
* '''two times flashes''' - receive IP from DHCP server - Wifi
* '''one time flashes''' - receive broadcast pair packet




!!How to mout to DIN rail
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-21.jpg]

!Firmware
[UDP packet format]
# Download and install last version [Arduino IDE|https://www.arduino.cc/en/Main/Software]
# Download and install ESP32 support for arduino from [GitHub|https://github.com/espressif/arduino-esp32] - prefered via ['''board manager'''|https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md].
# Download IP switch firmware source from [GitHub|https://github.com/ok1hra/IP_switch]
# Edit source
## For use '''Ethernet''' {.redka#id color: #f23f37}(prefered connection){/} wiring connection preset configuration{{#define ETHERNET               // Enable ESP32 ethernet (DHCP IPv4)
//#define WIFI                  // Enable ESP32 WIFI (DHCP IPv4)}}
## For use WiFi connection use this settings{{//#define ETHERNET               // Enable ESP32 ethernet (DHCP IPv4)
#define WIFI                  // Enable ESP32 WIFI (DHCP IPv4)}} and set your SSID and password for access{{const char* ssid     = "YOUR-SSID";
const char* password = "YOUR-PASSWORD";}}
# Select menu Tools/Board:"OLIMEX ESP32-GATEWAY"
# Connect micro USB between ESP32-GATEWAY and PC
# Select menu Tools/Port/YOUR-CONNECTED-PORT
# Upload firmware



!Setup
Setup are available via CLI (command line interface).
How to access
* connect micro USB cable
* run terminal - for example Ctrl+Shift+M in Arduino IDE
* set baudrate to 115200 and No line ending.
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-20.png|noborder]
CLI contains some commands for set or show information.
Commands for set source device
*'''m''' - Manual IP switch
*'''r''' - Band decoder MK2
*'''o''' - Open Interface III
Other commands, {.redka#id color: #f23f37}RED{/} is important
*'''?''' - show status and help
*'''w''' - set inactivity time in minutes, after them IP switch will be '''restarted (watchdog)'''
** before reboot store current output setting and restore after start
** zero value disable this watchdog 
*'''W''' - set inactivity time in minutes, after them IP switch will set '''all outputs to OFF'''
** if you need OFF all outputs after reboot watchdog, set smaller value than it
** zero value disable this watchdog 
*'''/''' - set {.redka#id color: #f23f37}encoder range{/} (2-g) for switching one from range
*'''%''' - enable/disable {.redka#id color: #f23f37}group buttons{/}
**'''!''' - SET group for each button separately
**''':''' - List group buttons
**in one group may be activate only one output
**groups are free configurable
**the group can be any size 2-8 buttons
**there may be any buttons in the group, for example 1 and 8
**the number of groups is not limited
*'''*''' - enable/disable serial debugging
*'''+''' - select get Network ID sufix from eeprom or hardware BCD switch
*'''#''' - set {.redka#id color: #f23f37}network ID{/}
**'''Prefix''' (four high bit) in hexadecimal format (0-f)
*** in standart mode prefix expanded range of network ID
*** if enable Multi control, prefix disable, and use only on master device for his idetifications
**'''Sufix''' (four low bit) in hexadecimal format (0-f)
***settings available if sufix get from eeprom
*** in standart mode sufix use for identification
*** in Multi control mode define group ID (id for all shared devices)
*'''$''' - enable/disable {.redka#id color: #f23f37}Multi control{/} function (sharing up to 16 master device)
*'''&''' - send broadcast packet for find control devices in local network
*'''.''' - if enable Multi control, show list detected IP switch by ID prefix
*'''@''' - restart IP switch 

!! For controlled from Manual IP switch
* Upload firmware by previous steps
* Set encoder range via CLI with command '''n'''
* Set source via CLI or web interface to '''m'''
* Set network ID prefix same on both devices via CLI in range 0-7
* Select Network ID sufix same on both devices with BCD switch in range '''ID 0-7'''{br}[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-bcd-switch.jpg|noborder]
* Connect to same local network with DHCP as Manual IP switch
* After power up both devices, is automaticaly pair

!!Web status page
[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-19.png|noborder]
* Show all outputs status
* Parameter of WiFi or ethrnet IP connect
* Firmware version
* Device uptime
* How source controled his
* {.redka#id color: #f23f37}Notice{/} - show this page can extend reaction latency IP switch

!!How IP addres got the device from the DHCP server?
* show in serial terminal after reboot, or send ? character
* or find some [network scanner|https://play.google.com/store/apps/details?id=com.overlook.android.fing&hl=en_GB]

!! Telnet access with access KEY
* Download and install [PuTTY|https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html]
* In menu Terminal preset CR/LF and line discipline by picture[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-22.png|noborder]
* In main menu Session select or set the following values [https://remoteqth.com/img/wiki-ip-switch-esp32gateway-23.png|noborder] 
** select '''Telnet'''
** port '''23'''
** write '''IP address'''
** Sessions may be saved for next time
** for connect press '''Open'''
* Login confirm with press '''y'''
* Now answer four times the question of what character is on random selected position, '''in your key'''
** you either get the key together with the IP-switch, or paste it into the source code{{const char* key="yWW3aaxjXua4wcoXUjkkOiAwChRwaUakVIfAUmmHV4ylwIXvN6Ucy3oH25T5ZzNYQ2r0L4s42tZIJT9XIgt9VVYxnDWtM7AVN6D8";}}[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-24.png|noborder] 
** if you enter wrong three times, login will be blocked for next ten minutes
* After login your IP address store to EEPROM and next key will be required '''only if change your IP''' address[https://remoteqth.com/img/wiki-ip-switch-esp32gateway-25.png|noborder]
* for '''Logout''' press '''q'''


!! Secure remote manage
Configuration available via serial CLI (command line interface). This interface can be safely accessed to the Internet and encrypted connections to manage all features
[https://remoteqth.com/img/wiki-manual-ipsw-07.png|noborder]
What you need
* any version Raspberry PI
* microSD card with [Raspbian Lite|https://www.raspberrypi.org/downloads/raspbian/]
* micro USB cable
* 5V power adapter with micro usb cable
* ethernet connection
* for first start HDMI monitor and USB keyboard

How to start
* after first boot login to serial console with default login '''pi''' and password '''raspberry'''
* run command and '''enable [SSH|https://www.raspberrypi.org/documentation/remote-access/ssh/]'''{{sudo raspi-config}}
* run command and write down the shown '''IP address'''{{ip a}}
* you can disconnect HDMI monitor and USB keyboard
* connect to Raspberry PI from any other PC
** [windows|https://www.raspberrypi.org/documentation/remote-access/ssh/windows.md]
** [Linux|https://www.raspberrypi.org/documentation/remote-access/ssh/unix.md]
** [iOS|https://www.raspberrypi.org/documentation/remote-access/ssh/ios.md]
* update system with run command{{sudo apt-get update && sudo apt-get upgrade}}
* install screen fith command {{sudo apt-get install screen}}
* run '''screen'''{{screen /dev/ttyUSB0 115200}}
* now after pres any key show status information and you can '''configure via CLI'''[https://remoteqth.com/img/wiki-manual-ipsw-cli.png|noborder]
* close screen with '''CTRL+A K''' and confirm '''y'''
* disconnect from Raspberry PI use command {{exit}}

[<-- Order page|https://remoteqth.com/order.php#ip-sw-mk2]
[<-- Web|https://remoteqth.com/ip-switch-mk2.php]
[<-- Control box|Manual IP switch II]