dev
This commit is contained in:
parent
e42891ae9e
commit
bd71011fe8
91
ESPBMS.ino
91
ESPBMS.ino
@ -1,4 +1,5 @@
|
||||
#include "BLEDevice.h"
|
||||
#include <ETH.h>
|
||||
|
||||
static BLEUUID serviceUUID("0000ff00-0000-1000-8000-00805f9b34fb"); //xiaoxiang bms service
|
||||
static BLEUUID charUUID_rx("0000ff01-0000-1000-8000-00805f9b34fb"); //xiaoxiang bms rx id
|
||||
@ -21,6 +22,7 @@ void setup() {
|
||||
char currentName[128];
|
||||
bool gotBasicInfo;
|
||||
bool gotCellInfo;
|
||||
static bool eth_ready = false;
|
||||
|
||||
void loop() {
|
||||
Serial.printf("\r\n\r\n===============================\r\n\r\n");
|
||||
@ -417,3 +419,92 @@ int16_t two_ints_into16(int highbyte, int lowbyte) // turns two bytes into a sin
|
||||
result = (result | lowbyte); //OR operation, merge the two
|
||||
return result;
|
||||
}
|
||||
|
||||
/////
|
||||
|
||||
/*
|
||||
* ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator
|
||||
* ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720
|
||||
* ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720
|
||||
* ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720
|
||||
*/
|
||||
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN // ETH_CLOCK_GPIO17_OUT
|
||||
|
||||
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
|
||||
#define ETH_POWER_PIN 16
|
||||
|
||||
// Type of the Ethernet PHY (LAN8720 or TLK110)
|
||||
#define ETH_TYPE ETH_PHY_LAN8720
|
||||
|
||||
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
|
||||
#define ETH_ADDR 1
|
||||
|
||||
// Pin# of the I²C clock signal for the Ethernet PHY
|
||||
#define ETH_MDC_PIN 23
|
||||
|
||||
// Pin# of the I²C IO signal for the Ethernet PHY
|
||||
#define ETH_MDIO_PIN 18
|
||||
|
||||
void WiFiEvent(WiFiEvent_t event) {
|
||||
Serial.print("E:");
|
||||
Serial.println(event);
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Serial.println("ETH Started");
|
||||
//set eth hostname here
|
||||
ETH.setHostname("esp32-ethernet");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Serial.println("ETH Connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Serial.print("ETH MAC: ");
|
||||
Serial.print(ETH.macAddress());
|
||||
Serial.print(", IPv4: ");
|
||||
Serial.print(ETH.localIP());
|
||||
if (ETH.fullDuplex()) {
|
||||
Serial.print(", FULL_DUPLEX");
|
||||
}
|
||||
Serial.print(", ");
|
||||
Serial.print(ETH.linkSpeed());
|
||||
Serial.println("Mbps");
|
||||
eth_ready = true;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Serial.println("ETH Disconnected");
|
||||
eth_ready = false;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Serial.println("ETH Stopped");
|
||||
eth_ready = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void eth_send(const char *data) {
|
||||
Serial.print("\nconnecting...");
|
||||
|
||||
WiFiClient client;
|
||||
if (!client.connect("10.6.0.1", 2003)) {
|
||||
Serial.println("connection failed");
|
||||
return;
|
||||
}
|
||||
client.print(data);
|
||||
while (client.connected() && !client.available());
|
||||
//long i;
|
||||
while (client.available()) {
|
||||
// i=i+1;
|
||||
Serial.write(client.read());
|
||||
// if(i==100){i=0; delay(1);}
|
||||
}
|
||||
|
||||
Serial.println("closing connection\n");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
void eth_begin() {
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
|
||||
}
|
||||
|
91
ethernet.ino
91
ethernet.ino
@ -1,91 +0,0 @@
|
||||
#include <Arduino.h>
|
||||
#include <ETH.h>
|
||||
|
||||
/*
|
||||
* ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator
|
||||
* ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720
|
||||
* ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720
|
||||
* ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720
|
||||
*/
|
||||
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN // ETH_CLOCK_GPIO17_OUT
|
||||
|
||||
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
|
||||
#define ETH_POWER_PIN 16
|
||||
|
||||
// Type of the Ethernet PHY (LAN8720 or TLK110)
|
||||
#define ETH_TYPE ETH_PHY_LAN8720
|
||||
|
||||
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
|
||||
#define ETH_ADDR 1
|
||||
|
||||
// Pin# of the I²C clock signal for the Ethernet PHY
|
||||
#define ETH_MDC_PIN 23
|
||||
|
||||
// Pin# of the I²C IO signal for the Ethernet PHY
|
||||
#define ETH_MDIO_PIN 18
|
||||
|
||||
static bool eth_ready = false;
|
||||
|
||||
void WiFiEvent(WiFiEvent_t event) {
|
||||
Serial.print("E:");
|
||||
Serial.println(event);
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Serial.println("ETH Started");
|
||||
//set eth hostname here
|
||||
ETH.setHostname("esp32-ethernet");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Serial.println("ETH Connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Serial.print("ETH MAC: ");
|
||||
Serial.print(ETH.macAddress());
|
||||
Serial.print(", IPv4: ");
|
||||
Serial.print(ETH.localIP());
|
||||
if (ETH.fullDuplex()) {
|
||||
Serial.print(", FULL_DUPLEX");
|
||||
}
|
||||
Serial.print(", ");
|
||||
Serial.print(ETH.linkSpeed());
|
||||
Serial.println("Mbps");
|
||||
eth_ready = true;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Serial.println("ETH Disconnected");
|
||||
eth_ready = false;
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Serial.println("ETH Stopped");
|
||||
eth_ready = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void eth_send(const char *data) {
|
||||
Serial.print("\nconnecting...");
|
||||
|
||||
WiFiClient client;
|
||||
if (!client.connect("10.6.0.1", 2003)) {
|
||||
Serial.println("connection failed");
|
||||
return;
|
||||
}
|
||||
client.print(data);
|
||||
while (client.connected() && !client.available());
|
||||
//long i;
|
||||
while (client.available()) {
|
||||
// i=i+1;
|
||||
Serial.write(client.read());
|
||||
// if(i==100){i=0; delay(1);}
|
||||
}
|
||||
|
||||
Serial.println("closing connection\n");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
void eth_begin() {
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
|
||||
}
|
Loading…
Reference in New Issue
Block a user