Skip to content

Commit 442be08

Browse files
committed
R133
1 parent 2d4c739 commit 442be08

File tree

6 files changed

+154
-56
lines changed

6 files changed

+154
-56
lines changed

Command.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ void ExecuteCommand(byte source, const char *Line)
2020
// commands for debugging
2121
// ****************************************
2222

23+
if (strcasecmp_P(Command, PSTR("SerialFloat")) == 0)
24+
{
25+
success = true;
26+
pinMode(1,INPUT);
27+
pinMode(3,INPUT);
28+
delay(60000);
29+
}
30+
2331
if (strcasecmp_P(Command, PSTR("meminfo")) == 0)
2432
{
2533
success = true;

ESPEasy.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
// MSP5611 I2C temp/baro sensor
6464
// BMP280 I2C Barometric Pressure sensor
6565
// SHT1X temperature/humidity sensors
66-
67-
// Experimental/Preliminary:
68-
// =========================
6966
// Ser2Net server
7067

7168
// ********************************************************************************
@@ -121,7 +118,7 @@
121118
#define ESP_PROJECT_PID 2015050101L
122119
#define ESP_EASY
123120
#define VERSION 9
124-
#define BUILD 132
121+
#define BUILD 133
125122
#define BUILD_NOTES ""
126123
#define FEATURE_SPIFFS false
127124

Misc.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,15 @@ boolean ruleMatch(String& event, String& rule)
19981998
String tmpEvent = event;
19991999
String tmpRule = rule;
20002000

2001+
// Special handling of literal string events, they should start with '!'
2002+
if (event.charAt(0) == '!')
2003+
{
2004+
if (event.equalsIgnoreCase(rule))
2005+
return true;
2006+
else
2007+
return false;
2008+
}
2009+
20012010
if (event.startsWith("Clock#Time")) // clock events need different handling...
20022011
{
20032012
int pos1 = event.indexOf("=");

WebServer.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ void handle_rules() {
25552555

25562556
// load form data from flash
25572557
reply += F("<form method='post'>");
2558-
reply += F("<textarea name='rules' rows='15' cols='80' wrap='on'>");
2558+
reply += F("<textarea name='rules' rows='15' cols='80' wrap='off'>");
25592559

25602560
#if FEATURE_SPIFFS
25612561
File f = SPIFFS.open("rules.txt", "r+");

_P020_Ser2Net.ino

Lines changed: 131 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
#define BUFFER_SIZE 128
1111
boolean Plugin_020_init = false;
12+
byte Plugin_020_SerialProcessing = 0;
1213

1314
WiFiServer *ser2netServer;
1415
WiFiClient ser2netClient;
1516

1617
boolean Plugin_020(byte function, struct EventStruct *event, String& string)
1718
{
1819
boolean success = false;
19-
static byte connectionState=0;
20+
static byte connectionState = 0;
2021

2122
switch (function)
2223
{
@@ -84,6 +85,29 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
8485
sprintf_P(tmpString, PSTR("<TR><TD>RX Receive Timeout (mSec):<TD><input type='text' name='plugin_020_rxwait' value='%u'>"), Settings.TaskDevicePluginConfig[event->TaskIndex][0]);
8586
string += tmpString;
8687

88+
byte choice2 = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
89+
String options2[3];
90+
options2[0] = F("None");
91+
options2[1] = F("Generic");
92+
options2[2] = F("RFLink");
93+
int optionValues2[3];
94+
optionValues2[0] = 0;
95+
optionValues2[1] = 1;
96+
optionValues2[2] = 2;
97+
string += F("<TR><TD>Event processing:<TD><select name='plugin_020_events'>");
98+
for (byte x = 0; x < 3; x++)
99+
{
100+
string += F("<option value='");
101+
string += optionValues2[x];
102+
string += "'";
103+
if (choice2 == optionValues2[x])
104+
string += F(" selected");
105+
string += ">";
106+
string += options2[x];
107+
string += F("</option>");
108+
}
109+
string += F("</select>");
110+
87111
success = true;
88112
break;
89113
}
@@ -102,6 +126,8 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
102126
ExtraTaskSettings.TaskDevicePluginConfigLong[4] = plugin5.toInt();
103127
String plugin6 = WebServer.arg("plugin_020_rxwait");
104128
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin6.toInt();
129+
String plugin7 = WebServer.arg("plugin_020_events");
130+
Settings.TaskDevicePluginConfig[event->TaskIndex][1] = plugin7.toInt();
105131
success = true;
106132
break;
107133
}
@@ -128,9 +154,10 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
128154
digitalWrite(Settings.TaskDevicePin1[event->TaskIndex], HIGH);
129155
pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
130156
}
131-
157+
132158
Plugin_020_init = true;
133159
}
160+
Plugin_020_SerialProcessing = Settings.TaskDevicePluginConfig[event->TaskIndex][1];
134161
success = true;
135162
break;
136163
}
@@ -151,7 +178,7 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
151178

152179
if (ser2netClient.connected())
153180
{
154-
connectionState=1;
181+
connectionState = 1;
155182
uint8_t net_buf[BUFFER_SIZE];
156183
int count = ser2netClient.available();
157184
if (count > 0)
@@ -169,22 +196,22 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
169196
strcpy_P(log, PSTR("Ser2N: network buffer full!")); // and log buffer full situation
170197
addLog(LOG_LEVEL_ERROR, log);
171198
}
172-
net_buf[count]=0; // before logging as a char array, zero terminate the last position to be safe.
173-
char log[BUFFER_SIZE+40];
199+
net_buf[count] = 0; // before logging as a char array, zero terminate the last position to be safe.
200+
char log[BUFFER_SIZE + 40];
174201
sprintf_P(log, PSTR("Ser2N: N>: %s"), (char*)net_buf);
175-
addLog(LOG_LEVEL_DEBUG,log);
202+
addLog(LOG_LEVEL_DEBUG, log);
176203
}
177204
}
178205
else
179206
{
180-
if(connectionState == 1) // there was a client connected before...
207+
if (connectionState == 1) // there was a client connected before...
181208
{
182-
connectionState=0;
209+
connectionState = 0;
183210
char log[40];
184211
strcpy_P(log, PSTR("Ser2N: Client disconnected!"));
185212
addLog(LOG_LEVEL_ERROR, log);
186213
}
187-
214+
188215
while (Serial.available())
189216
Serial.read();
190217
}
@@ -196,54 +223,107 @@ boolean Plugin_020(byte function, struct EventStruct *event, String& string)
196223

197224
case PLUGIN_SERIAL_IN:
198225
{
199-
if (Plugin_020_init)
226+
uint8_t serial_buf[BUFFER_SIZE];
227+
int RXWait = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
228+
if (RXWait == 0)
229+
RXWait = 1;
230+
int timeOut = RXWait;
231+
size_t bytes_read = 0;
232+
while (timeOut > 0)
200233
{
201-
if (ser2netClient.connected())
202-
{
203-
uint8_t serial_buf[BUFFER_SIZE];
204-
int RXWait = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
205-
if (RXWait == 0)
206-
RXWait = 1;
207-
int timeOut = RXWait;
208-
size_t bytes_read = 0;
209-
while (timeOut > 0)
210-
{
211-
while (Serial.available()) {
212-
if (bytes_read < BUFFER_SIZE) {
213-
serial_buf[bytes_read] = Serial.read();
214-
bytes_read++;
215-
}
216-
else
217-
Serial.read(); // when the buffer is full, just read remaining input, but do not store...
218-
219-
timeOut = RXWait; // if serial received, reset timeout counter
220-
}
221-
delay(1);
222-
timeOut--;
234+
while (Serial.available()) {
235+
if (bytes_read < BUFFER_SIZE) {
236+
serial_buf[bytes_read] = Serial.read();
237+
bytes_read++;
223238
}
224-
225-
if (bytes_read != BUFFER_SIZE)
239+
else
240+
Serial.read(); // when the buffer is full, just read remaining input, but do not store...
241+
242+
timeOut = RXWait; // if serial received, reset timeout counter
243+
}
244+
delay(1);
245+
timeOut--;
246+
}
247+
248+
if (bytes_read != BUFFER_SIZE)
249+
{
250+
if (bytes_read > 0) {
251+
if (Plugin_020_init && ser2netClient.connected())
226252
{
227-
if (bytes_read > 0) {
228-
ser2netClient.write((const uint8_t*)serial_buf, bytes_read);
229-
ser2netClient.flush();
230-
}
253+
ser2netClient.write((const uint8_t*)serial_buf, bytes_read);
254+
ser2netClient.flush();
231255
}
232-
else // if we have a full buffer, drop the last position to stuff with string end marker
233-
{
234-
while (Serial.available()) // read possible remaining data to avoid sending rubbish...
235-
Serial.read();
236-
bytes_read--;
237-
char log[40];
238-
strcpy_P(log, PSTR("Ser2N: serial buffer full!")); // and log buffer full situation
239-
addLog(LOG_LEVEL_ERROR, log);
240-
}
241-
serial_buf[bytes_read]=0; // before logging as a char array, zero terminate the last position to be safe.
242-
char log[BUFFER_SIZE+40];
243-
sprintf_P(log, PSTR("Ser2N: S>: %s"), (char*)serial_buf);
244-
addLog(LOG_LEVEL_DEBUG,log);
245256
}
257+
}
258+
else // if we have a full buffer, drop the last position to stuff with string end marker
259+
{
260+
while (Serial.available()) // read possible remaining data to avoid sending rubbish...
261+
Serial.read();
262+
bytes_read--;
263+
char log[40];
264+
strcpy_P(log, PSTR("Ser2N: serial buffer full!")); // and log buffer full situation
265+
addLog(LOG_LEVEL_ERROR, log);
266+
}
267+
serial_buf[bytes_read] = 0; // before logging as a char array, zero terminate the last position to be safe.
268+
char log[BUFFER_SIZE + 40];
269+
sprintf_P(log, PSTR("Ser2N: S>: %s"), (char*)serial_buf);
270+
addLog(LOG_LEVEL_DEBUG, log);
271+
272+
// We can also use the rules engine for local control!
273+
if (Settings.UseRules)
274+
{
275+
String message = (char*)serial_buf;
276+
int NewLinePos = message.indexOf("\r\n");
277+
if (NewLinePos > 0)
278+
message = message.substring(0, NewLinePos);
279+
String eventString = "";
280+
281+
switch (Plugin_020_SerialProcessing)
282+
{
283+
case 0:
284+
{
285+
break;
286+
}
287+
288+
case 1: // Generic
289+
{
290+
eventString = F("!Serial#");
291+
eventString += message;
292+
break;
293+
}
294+
295+
case 2: // RFLink
296+
{
297+
message = message.substring(6); // RFLink, strip 20;xx; from incoming message
298+
//message.replace("\r\n", "");
299+
if (message.startsWith("ESPEASY")) // Special treatment for gpio values, strip unneeded parts...
300+
{
301+
message = message.substring(8); // Strip "ESPEASY;"
302+
eventString = F("RFLink#");
303+
}
304+
else
305+
eventString = F("!RFLink#"); // default event as it comes in, literal match needed in rules, using '!'
306+
eventString += message;
307+
break;
308+
}
309+
} // switch
310+
311+
if (eventString.length() > 0)
312+
rulesProcessing(eventString);
313+
314+
} // if rules
315+
success = true;
316+
break;
317+
}
318+
319+
case PLUGIN_WRITE:
320+
{
321+
String command = parseString(string, 1);
322+
if (command == F("serialsend"))
323+
{
246324
success = true;
325+
String tmpString = string.substring(11);
326+
Serial.println(tmpString);
247327
}
248328
break;
249329
}

__ReleaseNotes.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// R133 26-09-2016
2+
// Added rule events to SerialServer and SerialSend command
3+
// Changed 'wrap on' to 'wrap off' in rules editor
4+
15
// R132 24-09-2016
26
// Moved ISR handlers for Pulse, RFID and HCSR04 plugins to iram cache
37

0 commit comments

Comments
 (0)