Skip to content

Commit

Permalink
Support for all RS232 pins added to modem software. Flow control
Browse files Browse the repository at this point in the history
hardware selectable.
  • Loading branch information
drdpj committed Jul 6, 2018
1 parent 81254ed commit 7c50287
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions esp_modem/esp_modem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

//#defines

//#define USE_HW_FLOW_CTRL // Use hardware (RTS/CTS) flow control - off by default, uncomment this line to use and then
#undef USE_HW_FLOW_CTRL // comment out this line!
#define USE_HW_FLOW_CTRL // Use hardware (RTS/CTS) flow control - off by default, uncomment this line to use and then
//#undef USE_HW_FLOW_CTRL // comment out this line!
#ifdef USE_HW_FLOW_CTRL
#include <uart_register.h>
#endif
Expand Down Expand Up @@ -131,16 +131,11 @@ void setup()
Serial.println();
Serial.print("DTR:");
Serial.println(digitalRead(ESP_DTR));
digitalWrite(ESP_DSR, 0);
digitalWrite(ESP_DCD, 1);
digitalWrite(ESP_RING, 1);


if (hwFlowOff == 0) {
digitalWrite(ESP_RING, 0);
digitalWrite(ESP_DCD, 1);
digitalWrite(ESP_DSR, 1);
} else {
digitalWrite(ESP_RING, 1);
digitalWrite(ESP_DCD, 0);
digitalWrite(ESP_DSR, 0);
}
if (LISTEN_PORT > 0)
{
Serial.print("Listening to connections at port ");
Expand Down Expand Up @@ -211,6 +206,7 @@ void command()
{
tcpClient.setNoDelay(true); // Try to disable naggle
Serial.print("CONNECT ");
digitalWrite(ESP_DCD,0);
Serial.println(myBps);
cmdMode = false;
Serial.flush();
Expand All @@ -219,6 +215,7 @@ void command()
else
{
Serial.println("NO CARRIER");
digitalWrite(ESP_DCD,1);
}
delete hostChr;
}
Expand Down Expand Up @@ -292,6 +289,7 @@ void command()
tcpClient = tcpServer.available();
tcpClient.setNoDelay(true); // try to disable naggle
tcpServer.stop();
digitalWrite(ESP_RING, 1);
Serial.print("CONNECT ");
Serial.println(myBps);
cmdMode = false;
Expand Down Expand Up @@ -346,10 +344,12 @@ void command()
if (!tcpClient.connect(hostChr, port))
{
Serial.println("NO CARRIER");
digitalWrite(ESP_DCD,1);
}
else
{
Serial.print("CONNECT ");
digitalWrite(ESP_DCD,0);
Serial.println(myBps);
cmdMode = false;

Expand Down Expand Up @@ -411,10 +411,13 @@ void loop()
if ((millis() - lastRingMs) > RING_INTERVAL)
{
Serial.println("RING");
digitalWrite(ESP_RING,0);
lastRingMs = millis();
}
} else {
digitalWrite(ESP_RING,1);
}

// In command mode - don't exchange with TCP but gather characters to a string
if (Serial.available())
{
Expand Down Expand Up @@ -580,6 +583,7 @@ void loop()
{
cmdMode = true;
Serial.println("NO CARRIER");
digitalWrite(ESP_DCD,1);
if (LISTEN_PORT > 0) tcpServer.begin();
}

Expand Down

0 comments on commit 7c50287

Please sign in to comment.