Merge branch 'ESP32WifiFINAL'

Resolved Conflicts in Arduino/SenderTrial2/SenderTrial2.ino
This commit is contained in:
rljonesau 2018-10-30 20:27:56 +11:00
commit dea11622ba
8 changed files with 230 additions and 4 deletions

View file

@ -0,0 +1,2 @@
// Place Holder Config File - User config vars and defines to be moved here
// Jimmy C

View file

@ -0,0 +1,86 @@
// Hopefully this code will be removed on the next commit as I dont think its required
//#define TELNET
#ifdef TELNET
#define DebugPort Debug
#endif
#ifndef TELNET
#define DebugPort DebugPort
#endif
#include "BTCTelnet.h"
#include "debugport.h"
WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS];
void initTelnet() {
server.begin();
server.setNoDelay(true);
DebugPort.print("Ready! Use 'telnet ");
DebugPort.print(WiFi.localIP());
DebugPort.println(" 23' to connect");
}
void doTelnet() {
uint8_t i;
//check if there are any new clients
if (server.hasClient()){
for(i = 0; i < MAX_SRV_CLIENTS; i++){
//find free/disconnected spot
if (!serverClients[i] || !serverClients[i].connected()){
if(serverClients[i]) serverClients[i].stop();
serverClients[i] = server.available();
if (!serverClients[i]) DebugPort.println("available broken");
DebugPort.print("New client: ");
DebugPort.print(i); DebugPort.print(' ');
DebugPort.println(serverClients[i].remoteIP());
break;
}
}
if (i >= MAX_SRV_CLIENTS) {
//no free/disconnected spot so reject
server.available().stop();
}
}
//check clients for data
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (serverClients[i] && serverClients[i].connected()){
if(serverClients[i].available()){
//get data from the telnet client and push it to the UART
while(serverClients[i].available()) DebugPort.write(serverClients[i].read());
}
}
else {
if (serverClients[i]) {
serverClients[i].stop();
}
}
}
//check UART for data
if(DebugPort.available()){
size_t len = DebugPort.available();
uint8_t sbuf[len];
DebugPort.readBytes(sbuf, len);
//push UART data to all connected telnet clients
for(i = 0; i < MAX_SRV_CLIENTS; i++){
if (serverClients[i] && serverClients[i].connected()){
serverClients[i].write(sbuf, len);
delay(1);
}
}
}
else {
DebugPort.println("WiFi not connected!");
for(i = 0; i < MAX_SRV_CLIENTS; i++) {
if (serverClients[i]) serverClients[i].stop();
}
delay(1000);
}
}

View file

@ -0,0 +1,9 @@
// Unfinished - Jimmy C 30/10/18
#include <Arduino.h>
#include "BTCWifi.h"
#define MAX_SRV_CLIENTS 2
void initTelnet();
void doTelnet();

View file

@ -0,0 +1,80 @@
// Should be working - Jimmy C
#include "BTCWifi.h"
// select which pin will trigger the configuration portal when set to LOW
WiFiManager wm;
unsigned int timeout = 120; // seconds to run for
unsigned int startTime = millis();
bool portalRunning = false;
bool startCP = false; // start AP and webserver if true, else start only webserver
int TRIG_PIN;
bool res;
void initWifi(int initpin,const char *failedssid, const char *failedpassword)
{
TRIG_PIN = initpin;
//reset settings - wipe credentials for testing
//wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
wm.setConfigPortalTimeout(20);
wm.setConfigPortalBlocking(false);
res = wm.autoConnect(); // auto generated AP name from chipid
if(!res) {
Serial.println("Failed to connect");
Serial.println("Setting up ESP as AP");
WiFi.softAP(failedssid, failedpassword);
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
void doWiFiManager(){
// is auto timeout portal running
if(portalRunning){
wm.process();
if((millis()-startTime) > (timeout*1000)){
Serial.println("portaltimeout");
portalRunning = false;
if(startCP){
wm.stopConfigPortal();
}
else{
wm.stopWebPortal();
}
}
}
// is configuration portal requested?
if(TRIG_PIN == 1 && (!portalRunning)) {
if(startCP){
Serial.println("Button Pressed, Starting Config Portal");
wm.setConfigPortalBlocking(false);
wm.startConfigPortal();
TRIG_PIN = 0; // reset the flag
}
else{
Serial.println("Button Pressed, Starting Web Portal");
wm.startWebPortal();
TRIG_PIN = 0; // reset the flag
}
portalRunning = true;
startTime = millis();
}
}

View file

@ -0,0 +1,11 @@
#include <Arduino.h>
#include <WiFiManager.h>
#include <WiFi.h>
/*
const char *failedssid;
const char *failedpassword;
*/
void doWiFiManager();
void initWifi(int initpin,const char *failedssid, const char *failedpassword);

View file

@ -3,6 +3,15 @@
#include "Protocol.h"
#include "debugport.h"
#ifdef TELNET
#define DebugPort Debug
#endif
#ifndef TELNET
#define DebugPort Serial
#endif
#ifdef ESP32
#define ESP32_USE_HC05
@ -88,7 +97,6 @@ void Bluetooth_Init()
// plough on and assume 9600 baud, but at the mercy of whatever the module name is...
DebugPort.println("FAILED to detect a HC-05 Bluetooth module :-(");
// leave the EN pin high - if other style module keeps it powered!
// assume it is 9600, and just (try to) use it like that...
// we will sense the STATE line to prove a client is hanging off the link...
DebugPort.println("ASSUMING a HC-05 module @ 9600baud (Unknown name)");

View file

@ -1,6 +1,15 @@
#include <Arduino.h>
#include "Protocol.h"
#include "debugport.h"
#ifdef TELNET
#define DebugPort Debug
#endif
#ifndef TELNET
#define DebugPort Serial
#endif
unsigned short
CProtocol::CalcCRC(int len) const

View file

@ -1,3 +1,4 @@
//
/*
Chinese Heater Half Duplex Serial Data Sending Tool
@ -68,9 +69,26 @@
#include "NVStorage.h"
#include "debugport.h"
#include "SmartError.h"
#include "BTCWifi.h"
#define HOST_NAME "remotedebug-sample"
#define TRIGGER_PIN 0
#define DEBUG_BTRX
#define FAILEDSSID "BTCESP32"
#define FAILEDPASSWORD "thereisnospoon"
//comment this out to remove TELNET
//#define TELNET
#ifdef TELNET
#define DebugPort Debug
#endif
#ifndef TELNET
#define DebugPort DebugPort
#endif
#define DEBUG_BTRX
#include "Bluetooth.h"
#if defined(__arm__)
@ -163,6 +181,8 @@ void PrepareTxFrame(const CProtocol& basisFrame, CProtocol& TxFrame, bool isBTCm
void setup()
{
initWifi(TRIGGER_PIN, FAILEDSSID, FAILEDPASSWORD);
pinMode(Tx2Pin, OUTPUT);
digitalWrite(Tx2Pin, HIGH);
pinMode(Rx2Pin, INPUT_PULLUP);
@ -219,8 +239,10 @@ void setup()
void loop()
{
unsigned long timenow = millis();
doWiFiManager();
// check for test commands received from PC Over USB
if(DebugPort.available()) {
char rxval = DebugPort.read();
if(rxval == '+') {
@ -494,4 +516,3 @@ void Command_Interpret(const char* pLine)
}
}