1
0
mirror of https://github.com/Adam-Ant/MQTT-nRF24-Bridge synced 2024-12-20 07:34:35 +00:00

Add spiffs web data, and start of input processing

This commit is contained in:
Adam Dodman 2018-01-27 17:23:12 +00:00
parent 031833ca9f
commit 1a1001bca3
4 changed files with 58 additions and 31 deletions

3
.gitmodules vendored
View File

@ -7,3 +7,6 @@
[submodule "lib/RF24Mesh"]
path = lib/RF24Mesh
url = git@github.com:nRF24/RF24Mesh.git
[submodule "lib/ArduinoJson"]
path = lib/ArduinoJson
url = git@github.com:bblanchon/ArduinoJson.git

40
data/index.html Normal file
View File

@ -0,0 +1,40 @@
<html>
<head>
<title>ESP8266 Input Example</title>
<style>
body {
background-color: #E6E6FA;
font-family: Arial, Helvetica, Sans-Serif;
Color: blue;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
var counter = 1;
function addInput(tableName){
var newrow = document.createElement('tr');
newrow.innerHTML = "<td><input type='text' name='mqtt" + counter + "'></td><td><input type='text' name='node" + counter + "'></td>"
document.getElementById(tableName).appendChild(newrow);
counter++;
}
</script>
</head>
<body>
<h1><br>ESP8266 Server - Getting input from a client</h1>
<form action='/submit' method='POST'>
<table id='dynamicInput'>
<tr>
<th>MQTT Address</th>
<th>Node ID</th>
</tr>
<tr><td><input type='text' name='mqtt0'></td><td><input type='text' name='node0'></td></tr>
</table>
<input type='submit' value='Enter'> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');">
</form>
</body>
</html>

1
lib/ArduinoJson Submodule

@ -0,0 +1 @@
Subproject commit cf5396aaed6d16d1fb4e73b82ce6606938591043

View File

@ -1,26 +1,14 @@
/** RF24Mesh_Example_Master.ino by TMRh20
*
*
* This example sketch shows how to manually configure a node via RF24Mesh as a master node, which
* will receive all data from sensor nodes.
*
* The nodes can change physical or logical position in the network, and reconnect through different
* routing nodes as required. The master node manages the address assignments for the individual nodes
* in a manner similar to DHCP.
*
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include "FS.h"
#include "RF24Network.h"
#include "RF24.h"
#include "RF24Mesh.h"
#include <SPI.h>
//Include eeprom.h for AVR (Uno, Nano) etc. except ATTiny
#include <EEPROM.h>
const char* ssid = "XXXX";
const char* password = "XXXX";
@ -32,8 +20,6 @@ RF24Mesh mesh(radio,network);
ESP8266WebServer http(80);
uint32_t displayTimer = 0;
String webpage = "";
@ -59,7 +45,7 @@ void setup() {
Serial.println(WiFi.localIP());
// Setup the web server
http.on("/", [](){
http.on("/clients", [](){
webpage = "<h1>Connected Clients:</h1><br>";
for(int i=0; i<mesh.addrListTop; i++){
webpage += "<b>NodeId: </b>";
@ -70,8 +56,18 @@ void setup() {
http.send(200, "text/html", webpage);
});
http.serveStatic("/", SPIFFS, "/index.html");
http.begin();
if (!SPIFFS.begin()) {
Serial.println("Failed to mount file system");
return;
}
//TODO: Add SPiffs web site. JQuery to jsonify and post. Post JSON data, parse and validate, and store. Call load function to load it into arrays. MQTT message routing. Connected clients on wesbite, js to update
}
@ -98,17 +94,4 @@ void loop() {
default: network.read(header,0,0); Serial.println(header.type);break;
}
}
if(millis() - displayTimer > 5000){
displayTimer = millis();
Serial.println(" ");
Serial.println(F("********Assigned Addresses********"));
for(int i=0; i<mesh.addrListTop; i++){
Serial.print("NodeID: ");
Serial.print(mesh.addrList[i].nodeID);
Serial.print(" RF24Network Address: 0");
Serial.println(mesh.addrList[i].address,OCT);
}
Serial.println(F("**********************************"));
}
}