sorry bad english!
This project uses expressif ESP32-S/ESP32 module, AS01-ML01DP5 NRF24L01+PA wireless transceiver module. and use serial bridge to display the gateway log by telnet !
this is my frist project , Thank you for your suggestion!
broad Gateways esp32 can be unshared or shared of one ams1117-sot89-3.3 , another ams1117 is desgin for nrf24 with 6032 227j tantalum capacitors . Power supply selection using SMD PIN on the PCB back !
PCB back with urx utx pinpad for serial bridge by use ttl itself ,very convenient use ttyd-web with esp32-gw ttl log!
when you flash esp32 ,plese keep Unconnected utx urx pinpad , and flash pad with 1.27 V-G-R-T-0 ,maybe some ttl RX TX Need to adjust!
/*
The MySensors Arduino library handles the wireless radio link and protocol
between your home built sensors/actuators and HA controller of choice.
The sensors forms a self healing radio network with optional repeaters. Each
repeater and gateway builds a routing tables in EEPROM which keeps track of the
network topology allowing messages to be routed to nodes.
Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
Copyright (C) 2013-2018 Sensnology AB
Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
Documentation: http://www.mysensors.org
Support Forum: http://forum.mysensors.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*******************************
REVISION HISTORY
Version 1.0 - tekka
DESCRIPTION
The ESP32 gateway sends data received from sensors to the WiFi link.
The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
Make sure to fill in your ssid and WiFi password below.
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enables and select radio type (if attached)
#define MY_RADIO_RF24
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
#define MY_BAUD_RATE 115200
#define MY_GATEWAY_ESP32
#define MY_WIFI_SSID "WIFI-name"
#define MY_WIFI_PASSWORD "WIFI-pass"
// Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static.
#define MY_HOSTNAME "ESP32_GW"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,1,100
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// The port to keep open on node server mode
#define MY_PORT 5003
// How many clients should be able to connect to this gateway (default 1)
#define MY_GATEWAY_MAX_CLIENTS 5
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 32 // Transfer data error led pin
#define MY_DEFAULT_RX_LED_PIN 25 // Receive Data led pin
#define MY_DEFAULT_TX_LED_PIN 27 // Transmit Data led pin
/************************* COM Port 0 *******************************/
#define UART_BAUD0 115200 // Baudrate UART0
#define SERIAL_PARAM0 SERIAL_8N1 // Data/Parity/Stop UART0
#define SERIAL0_RXPIN 14 // receive Pin UART0
#define SERIAL0_TXPIN 12 // transmit Pin UART0
#define SERIAL0_TCP_PORT 23 // Wifi Port UART0
#define MAX_NMEA_CLIENTS 4
#define NUM_COM 1 // total number of COM Ports
#define bufferSize 1024
HardwareSerial Serial_one(1);
HardwareSerial* COM[NUM_COM] = {&Serial_one};
#include <MySensors.h>
#include <esp_wifi.h>
#include <WiFi.h>
#include <WiFiClient.h>
WiFiServer server_0(SERIAL0_TCP_PORT);
WiFiServer *server[NUM_COM] = {&server_0};
WiFiClient TCPClient[NUM_COM][MAX_NMEA_CLIENTS];
uint8_t buf1[bufferSize];
uint8_t i1=0;
uint8_t buf2[bufferSize];
uint8_t i2=0;
bool debug = true;
void setup()
{
COM[0]->begin(UART_BAUD0, SERIAL_PARAM0, SERIAL0_RXPIN, SERIAL0_TXPIN);
server[0]->begin(); // start TCP server
server[0]->setNoDelay(true);
esp_err_t esp_wifi_set_max_tx_power(50); //lower WiFi Power
}
void presentation()
{
// Present locally attached sensors here
}
void loop()
{
for (int num = 0; num < NUM_COM ; num++)
{
if (server[num]->hasClient())
{
for (byte i = 0; i < MAX_NMEA_CLIENTS; i++) {
//find free/disconnected spot
if (!TCPClient[num][i] || !TCPClient[num][i].connected()) {
if (TCPClient[num][i]) TCPClient[num][i].stop();
TCPClient[num][i] = server[num]->available();
continue;
}
}
//no free/disconnected spot so reject
WiFiClient TmpserverClient = server[num]->available();
TmpserverClient.stop();
}
}
for (int num = 0; num < NUM_COM ; num++)
{
if (COM[num] != NULL)
{
for (byte cln = 0; cln < MAX_NMEA_CLIENTS; cln++)
{
if (TCPClient[num][cln])
{
while (TCPClient[num][cln].available())
{
buf1[i1] = TCPClient[num][cln].read(); // read char from client (LK8000 app)
if (i1 < bufferSize - 1) i1++;
}
COM[num]->write(buf1, i1); // now send to UART(num):
i1 = 0;
}
}
if (COM[num]->available())
{
while (COM[num]->available())
{
buf2[i2] = COM[num]->read(); // read char from UART(num)
if (i2 < bufferSize - 1) i2++;
}
// now send to WiFi:
for (byte cln = 0; cln < MAX_NMEA_CLIENTS; cln++)
{
if (TCPClient[num][cln])
TCPClient[num][cln].write(buf2, i2);
}
i2 = 0;
}
}
}
}
��I D |
---|