Skip to content

Commit

Permalink
Web Send Message stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
couin3 committed Apr 30, 2020
1 parent ec32c08 commit 860384c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 8 deletions.
34 changes: 31 additions & 3 deletions RFLink/3_Serial.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// ************************************* //
// ************************************* //
// * Arduino Project RFLink-esp * //
// * https://github.com/couin3/RFLink * //
// * 2018..2020 Stormteam - Marc RIVES * //
Expand Down Expand Up @@ -34,9 +34,9 @@ boolean CheckSerial()
return false;
}

boolean CheckMQTT(byte *mqtt_in)
boolean CheckMQTT(byte *byte_in)
{
if (CopySerial((char *)mqtt_in))
if (CopySerial((char *)byte_in))
{
#ifdef SERIAL_ENABLED
Serial.flush();
Expand All @@ -49,6 +49,34 @@ boolean CheckMQTT(byte *mqtt_in)
return false;
}

boolean CheckWeb(String &String_in)
{
if (!String_in.isEmpty())
{
String_in.trim();
char char_in[INPUT_COMMAND_SIZE];
String_in.toCharArray(char_in, String_in.length() + 1);
char_in[String_in.length() + 1] = 0;

if (CopySerial(char_in))
{
#ifdef SERIAL_ENABLED
Serial.flush();
Serial.print(F("Message arrived [Web] "));
Serial.println(InputBuffer_Serial);
#endif
if (CheckCmd())
{
String_in.clear();
return true;
}
}
String_in.clear();
return false;
}
return false;
}

boolean CopySerial(char *src)
{
return (strncpy(InputBuffer_Serial, src, INPUT_COMMAND_SIZE - 2));
Expand Down
1 change: 1 addition & 0 deletions RFLink/3_Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ extern char InputBuffer_Serial[INPUT_COMMAND_SIZE];

boolean CheckSerial();
boolean CheckMQTT(byte *);
boolean CheckWeb(String &);

#endif
1 change: 0 additions & 1 deletion RFLink/6_WiFi_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern String MQTT_TOPIC_IN;
extern boolean MQTT_RETAINED;
extern String Adv_HostName;
extern String Adv_Power;
extern String LastMsg;
#else
#ifdef ESP32
#include <WiFi.h>
Expand Down
30 changes: 26 additions & 4 deletions RFLink/9_AutoConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// * Arduino Project RFLink-esp * //
// * https://github.com/couin3/RFLink * //
// * 2018..2020 Stormteam - Marc RIVES * //
// * 2020 Schmutzm, Autoconnect Stuff * //
// * 2020 Allexum, Web "Send" button * //
// * More details in RFLink.ino file * //
// ************************************* //

Expand Down Expand Up @@ -43,6 +45,7 @@ boolean MQTT_RETAINED;
String Adv_HostName;
String Adv_Power;
String LastMsg;
String CmdMsg;
// Radio pins settings
uint8_t PIN_RF_RX_PMOS;
uint8_t PIN_RF_RX_NMOS;
Expand All @@ -65,6 +68,13 @@ void rootPage()
{

WebServer &webServer = portal.host();

if (webServer.hasArg("BtnSend"))
{
// Récupération de la valeur dans la fenêtre Send
CmdMsg = webServer.arg(0);
}

if (webServer.hasArg("BtnSave"))
{ // On n'enregistre les values que si ce n'est pas le bouton "test" qui a été appuyé

Expand Down Expand Up @@ -199,13 +209,25 @@ void rootPage()
//==========================================
content += " </div>";
content += "</div>";

content += "<form action='/' method='POST'><button type='button submit' name='BtnTimeBeforeSWoff' value='0' class='btn btn-secondary'>Refresh</button></form>";
content += "<Br>";

content += "<form action='/' method='POST'><button type='button submit' name='BtnTimeBeforeSWoff' value='0' class='btn btn-secondary'>Refresh</button></form><Br>";
// Zone de saisaie du message à envoyer
content += "<form action='/' method='POST'>";
content += "<div class='card bg-light mb-3' style='max-width: 50rem;'>";
content += " <div class='card-header'>Send Message</div>";
content += " <div class='card-body'>";
if (webServer.hasArg("BtnSend"))
content += "<input type='text' id='send' name='send' size='60' value='" + webServer.arg(0) + "'>";
else
content += "<input type='text' id='send' name='send' size='60' placeholder='10;PING; '>";
content += " </div>";
content += "</div>";
content += "<button type='button submit' name='BtnSend' value='0' class='btn btn-secondary'>Send</button></form>";
content += "<Br>";

content += "<table class='table table-hover' style='max-width: 50rem;'>";
content += "<thead><tr><th>N&deg;</th><th>Name</th><th>Enabled</th></tr></thead>"; // Table Header // é = &eacute;
content += "<thead><tr><th>N&deg;</th><th>Plugin Name</th><th>Enabled</th></tr></thead>"; // Table Header // é = &eacute;
content += "<tbody>"; // Table content
content += "<form action='/' method='POST'>";
for (byte x = 0; x < PLUGIN_MAX; x++)
Expand Down Expand Up @@ -236,7 +258,7 @@ void rootPage()
content += "</tr><tr><td></td><td></td><td></td></tr>"; // we add a last line to bottom of the table
content += "</tbody></table>";

content += "<button type='button submit' name='BtnSave' value='0' class='btn btn-success btn-lg'>save</button></form></div>";
content += "<button type='button submit' name='BtnSave' value='0' class='btn btn-secondary'>Save</button></form></div>";

content += "</body>";
content += "</html>";
Expand Down
3 changes: 3 additions & 0 deletions RFLink/9_AutoConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#ifdef AUTOCONNECT_ENABLED

extern String LastMsg;
extern String CmdMsg;

#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif ESP32
Expand Down
5 changes: 5 additions & 0 deletions RFLink/RFLink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ void loop()
sendMsg();
#endif

#ifdef AUTOCONNECT_ENABLED
if(CheckWeb(CmdMsg))
sendMsg();
#endif

if (ScanEvent())
sendMsg();

Expand Down

0 comments on commit 860384c

Please sign in to comment.