dev
This commit is contained in:
parent
4f555200a5
commit
39cc68c4d9
74
ESPBMS.ino
74
ESPBMS.ino
@ -5,6 +5,7 @@
|
|||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include "ca_cert.h"
|
#include "ca_cert.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
// NTP Client setup
|
// NTP Client setup
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
@ -36,27 +37,21 @@ void setup() {
|
|||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
client.setCACert(ca_cert);
|
client.setCACert(ca_cert);
|
||||||
client.setHandshakeTimeout(5);
|
client.setHandshakeTimeout(5);
|
||||||
|
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
|
||||||
BLEDevice::init(""); // Initialize BLE device
|
BLEDevice::init(""); // Initialize BLE device
|
||||||
}
|
}
|
||||||
|
|
||||||
bool client_connect(){
|
bool client_connect(){
|
||||||
//https.setTimeout(preferences.getInt("http_timeout"));
|
//https.setTimeout(preferences.getInt("http_timeout"));
|
||||||
//https.setConnectTimeout(preferences.getInt("http_timeout"));
|
//https.setConnectTimeout(preferences.getInt("http_timeout"));
|
||||||
https.addHeader("Content-Type","application/x-www-form-urlencoded");
|
//https.addHeader("Content-Type","application/x-www-form-urlencoded");
|
||||||
String url="https://jhodges.co.uk/test.php";
|
String url="URL";
|
||||||
|
https.end();
|
||||||
if(!https.begin(client, url)) { // HTTPS
|
if(!https.begin(client, url)) { // HTTPS
|
||||||
Serial.println("connect fail");
|
Serial.println("connect fail");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println("connect ok");
|
Serial.println("connect ok");
|
||||||
int httpCode=https.POST("TEST");
|
|
||||||
if(httpCode==200){
|
|
||||||
Serial.println("post ok");
|
|
||||||
}else{
|
|
||||||
Serial.print("post fail:");
|
|
||||||
Serial.println(httpCode);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +71,7 @@ void loop() {
|
|||||||
delay(250);
|
delay(250);
|
||||||
}
|
}
|
||||||
timeClient.update();
|
timeClient.update();
|
||||||
|
//testClient("www.google.com", 80);
|
||||||
client_connect();
|
client_connect();
|
||||||
|
|
||||||
for (int i = 0; i < foundDevices.getCount(); i++) {
|
for (int i = 0; i < foundDevices.getCount(); i++) {
|
||||||
@ -85,6 +81,8 @@ void loop() {
|
|||||||
BLEAdvertisedDevice advertisedDevice = foundDevices.getDevice(i);
|
BLEAdvertisedDevice advertisedDevice = foundDevices.getDevice(i);
|
||||||
Serial.println("\nFound Device: " + String(advertisedDevice.toString().c_str()));
|
Serial.println("\nFound Device: " + String(advertisedDevice.toString().c_str()));
|
||||||
|
|
||||||
|
client_connect();
|
||||||
|
|
||||||
std::string targetAddress = "d0:65:de:e5:89:76";
|
std::string targetAddress = "d0:65:de:e5:89:76";
|
||||||
if (advertisedDevice.getAddress().toString() == targetAddress) {
|
if (advertisedDevice.getAddress().toString() == targetAddress) {
|
||||||
Serial.println("Victron device found!");
|
Serial.println("Victron device found!");
|
||||||
@ -531,51 +529,25 @@ void eth_send(const char* format, Args... args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eth_send(const char *data) {
|
void eth_send(const char *data) {
|
||||||
Serial.print("connecting...\r\n");
|
if(!https.connected()){
|
||||||
|
https.end();
|
||||||
WiFiClient client;
|
client_connect();
|
||||||
if (!client.connect("ecomotus.home.arpa", 2003)) {
|
}
|
||||||
Serial.println("connection failed");
|
Serial.print("http connecting...\r\n");
|
||||||
return;
|
Serial.printf("ETH Send: %s\r\n", data);
|
||||||
|
int httpCode=https.POST(data);
|
||||||
|
if(httpCode==200){
|
||||||
|
Serial.println("post ok");
|
||||||
|
while (client.available()) {
|
||||||
|
Serial.write(client.read());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Serial.print("post fail:");
|
||||||
|
Serial.println(httpCode);
|
||||||
}
|
}
|
||||||
unsigned long epochTime = timeClient.getEpochTime();
|
|
||||||
client.printf("%s %lu\r\n", data, epochTime);
|
|
||||||
Serial.printf("ETH Send: %s %lu\r\n", data, epochTime);
|
|
||||||
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() {
|
void eth_begin() {
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
|
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testClient(const char * host, uint16_t port) {
|
|
||||||
Serial.print("\nconnecting to ");
|
|
||||||
Serial.println(host);
|
|
||||||
|
|
||||||
WiFiClient client;
|
|
||||||
if (!client.connect(host, port)) {
|
|
||||||
Serial.println("connection failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user