kopia lustrzana https://github.com/sh123/esp32_loraprs
Added support for soft ap
rodzic
ce40ff98d2
commit
3ce9c99679
|
@ -16,6 +16,7 @@ Service::Service()
|
||||||
, csmaSlotTimePrev_(0)
|
, csmaSlotTimePrev_(0)
|
||||||
, serialBt_()
|
, serialBt_()
|
||||||
, serialBLE_()
|
, serialBLE_()
|
||||||
|
, kissServer_(new WiFiServer(CfgKissPort))
|
||||||
{
|
{
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
interruptEnabled_ = true;
|
interruptEnabled_ = true;
|
||||||
|
@ -66,6 +67,7 @@ void Service::setupWifi(const String &wifiName, const String &wifiKey)
|
||||||
Serial.print("WIFI connecting to " + wifiName);
|
Serial.print("WIFI connecting to " + wifiName);
|
||||||
|
|
||||||
WiFi.setHostname("loraprs");
|
WiFi.setHostname("loraprs");
|
||||||
|
if (config_.WifiEnableAp) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
WiFi.begin(wifiName.c_str(), wifiKey.c_str());
|
||||||
|
|
||||||
|
@ -80,6 +82,13 @@ void Service::setupWifi(const String &wifiName, const String &wifiKey)
|
||||||
}
|
}
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
} else {
|
||||||
|
WiFi.softAP(wifiName.c_str(), wifiKey.c_str());
|
||||||
|
Serial.println(WiFi.softAPIP());
|
||||||
|
}
|
||||||
|
if (config_.KissEnableTcpIp) {
|
||||||
|
kissServer_->begin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::reconnectWifi() const
|
void Service::reconnectWifi() const
|
||||||
|
@ -98,6 +107,11 @@ void Service::reconnectWifi() const
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
if (config_.KissEnableTcpIp) {
|
||||||
|
kissServer_->begin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Service::reconnectAprsis()
|
bool Service::reconnectAprsis()
|
||||||
|
@ -527,9 +541,28 @@ void Service::onRigTxEnd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFiClient Service::getClient()
|
||||||
|
{
|
||||||
|
if (config_.KissEnableTcpIp) {
|
||||||
|
WiFiClient client = kissServer_->available();
|
||||||
|
if (client) {
|
||||||
|
|
||||||
|
if (client.connected()) {
|
||||||
|
Serial.println("Connected to client");
|
||||||
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Service::onSerialTx(byte b)
|
void Service::onSerialTx(byte b)
|
||||||
{
|
{
|
||||||
if (config_.BtEnableBle) {
|
WiFiClient client = getClient();
|
||||||
|
if (client) {
|
||||||
|
client.write(b);
|
||||||
|
}
|
||||||
|
else if (config_.BtEnableBle) {
|
||||||
serialBLE_.write(b);
|
serialBLE_.write(b);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -539,7 +572,11 @@ void Service::onSerialTx(byte b)
|
||||||
|
|
||||||
bool Service::onSerialRxHasData()
|
bool Service::onSerialRxHasData()
|
||||||
{
|
{
|
||||||
if (config_.BtEnableBle) {
|
WiFiClient client = getClient();
|
||||||
|
if (client) {
|
||||||
|
return client.available();
|
||||||
|
}
|
||||||
|
else if (config_.BtEnableBle) {
|
||||||
return serialBLE_.available();
|
return serialBLE_.available();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -549,10 +586,17 @@ bool Service::onSerialRxHasData()
|
||||||
|
|
||||||
bool Service::onSerialRx(byte *b)
|
bool Service::onSerialRx(byte *b)
|
||||||
{
|
{
|
||||||
int rxResult = config_.BtEnableBle
|
int rxResult;
|
||||||
|
|
||||||
|
WiFiClient client = getClient();
|
||||||
|
if (client) {
|
||||||
|
rxResult = client.read();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rxResult = config_.BtEnableBle
|
||||||
? serialBLE_.read()
|
? serialBLE_.read()
|
||||||
: serialBt_.read();
|
: serialBt_.read();
|
||||||
|
}
|
||||||
if (rxResult == -1) {
|
if (rxResult == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,8 @@ private:
|
||||||
#endif
|
#endif
|
||||||
void onAprsisDataAvailable();
|
void onAprsisDataAvailable();
|
||||||
|
|
||||||
|
WiFiClient getClient();
|
||||||
|
|
||||||
void sendSignalReportEvent(int rssi, float snr);
|
void sendSignalReportEvent(int rssi, float snr);
|
||||||
void sendPeriodicBeacon();
|
void sendPeriodicBeacon();
|
||||||
void sendToAprsis(const String &aprsMessage);
|
void sendToAprsis(const String &aprsMessage);
|
||||||
|
@ -106,6 +108,8 @@ private:
|
||||||
const long CfgCsmaPersistence = 100; // 255 for real time, lower for higher traffic
|
const long CfgCsmaPersistence = 100; // 255 for real time, lower for higher traffic
|
||||||
const long CfgCsmaSlotTimeMs = 500; // 0 for real time, otherwise set to average tx duration
|
const long CfgCsmaSlotTimeMs = 500; // 0 for real time, otherwise set to average tx duration
|
||||||
|
|
||||||
|
// kiss static parameters
|
||||||
|
const int CfgKissPort = 8081; // kiss tcp/ip server port
|
||||||
private:
|
private:
|
||||||
// config
|
// config
|
||||||
Config config_;
|
Config config_;
|
||||||
|
@ -131,6 +135,7 @@ private:
|
||||||
BluetoothSerial serialBt_;
|
BluetoothSerial serialBt_;
|
||||||
BLESerial serialBLE_;
|
BLESerial serialBLE_;
|
||||||
WiFiClient aprsisConn_;
|
WiFiClient aprsisConn_;
|
||||||
|
std::shared_ptr<WiFiServer> kissServer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // LoraPrs
|
} // LoraPrs
|
||||||
|
|
Ładowanie…
Reference in New Issue