Browse Source

structure cleaning

removed include.h
put needed includes within each thumb, with redundancy
removed all uki
Etienne Landon 8 years ago
parent
commit
7c2333e2f3
7 changed files with 132 additions and 133 deletions
  1. 0 50
      ESP_UKI.ino
  2. 0 41
      includes.h
  3. 12 0
      osc.h
  4. 7 0
      ota.h
  5. 60 0
      tens_esp.ino
  6. 17 21
      udp.h
  7. 36 21
      wifimgr.h

+ 0 - 50
ESP_UKI.ino

@@ -1,50 +0,0 @@
-/*
-    ESP_UKI
-
-  TODO :  better function organizing
-          add firmware number in webserver
-          send ADC to default IP via udp, allow configuration
-
-         build onDemand config mode
-         load/save parameters (fixed ip, uki_name, udp_port udp_ip
-*/
-
-
-#include "includes.h"  //headers and variables declaration
-
-
-
-
-
-void setup ( void ) {
-  
-  delay(500) ;
-  Serial.begin(115200);
-  Serial.println("Starting ESP8266");
-
-  setupLeds();
-  
-  setupWifi(); 
-
-  setupUDP() ;
-  
-  //setupOTA();
- 
-  blueLedState(-1, 500);
-  
-  
-}
-
-
-void loop ( void ) {
-  //Serial.println(WiFi.status());
-  StartConfigAP();
-  //checkOTA();
-  UDP_send_receive();
-
-  
-}
-
-
-
-

+ 0 - 41
includes.h

@@ -1,41 +0,0 @@
-
-
-#include <FS.h>                   //this needs to be first, or it all crashes and burns...
-
-#include <ESP8266WiFi.h>
-//#include <WiFiClient.h>
-//#include <ESP8266WebServer.h>
-//web config portal
-#include <ESP8266WebServer.h>
-#include <DNSServer.h>
-#include <WiFiManager.h>
-
-#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson
-
-#include <Ticker.h>
-#include <WiFiUdp.h>
-
-//OTA includes
-#include <ESP8266mDNS.h>
-#include <ArduinoOTA.h>
-
-
-//ESP8266WebServer server(80); 
-
-WiFiUDP UKI_UDP;
-
-
-#include "leds.h"     //config and functions relative to leds
-
-#include "ota.h"      //config and functions relative to ota firmware updates
-#include "wifimgr.h"   //config and functions relative to wifi and access point configuration and configuration permanent saving
-
-
-#include "udp.h"  //some helpers functions
-
-
-
-
-
-
-

+ 12 - 0
osc.h

@@ -0,0 +1,12 @@
+//OSC via udp
+#include <WiFiUdp.h>
+#include <OSCMessage.h>
+
+WiFiUDP UDP; //udp listener
+
+/* UDP CONFIGURATION */
+int UDP_In_Port = 9000;  //udp port input for ESP
+
+//default address and port to send to (IP read from config)
+IPAddress UDP_Out_IP ;
+int UDP_Out_Port = 8000 ;

+ 7 - 0
ota.h

@@ -1,3 +1,10 @@
+#include <ESP8266WiFi.h>
+#include <ESP8266mDNS.h>
+#include <WiFiUdp.h>
+#include <ArduinoOTA.h>
+
+
+
 Ticker tkOTA;  // periodic check if OTA available
 int OTA_check_ms = 100;
 bool flag_OTA = false;

+ 60 - 0
tens_esp.ino

@@ -0,0 +1,60 @@
+/*
+    TENS_ESP
+
+ *remove UKI references (names etc)
+ *build OSC commmunication style (cf M_Lavenne)
+ *use multicast (see udp_multicast2)
+ *create digipot control functions
+ *create ID message filtering system using "ESP_NAME"
+ *add multicast configuration option (0 or 1)
+
+*/
+
+#include <Ticker.h>
+
+
+
+
+
+#include "leds.h"     //config and functions relative to leds
+#include "ota.h"      //config and functions relative to ota firmware updates
+#include "wifimgr.h"   //config and functions relative to wifi and access point configuration and configuration permanent saving
+
+
+#include "osc.h"  //some helpers functions
+
+
+
+
+void setup ( void ) {
+  
+  delay(500) ;
+  Serial.begin(115200);
+  Serial.println("Starting ESP8266");
+
+  setupLeds();
+  
+  setupWifi(); 
+
+  //setupUDP() ;
+  
+  //setupOTA();
+ 
+  blueLedState(-1, 500);
+  
+  
+}
+
+
+void loop ( void ) {
+  //Serial.println(WiFi.status());
+  StartConfigAP();
+  //checkOTA();
+  //UDP_send_receive();
+
+  
+}
+
+
+
+

+ 17 - 21
udp.h

@@ -1,11 +1,6 @@
-/* UDP CONFIGURATION */
-int UKI_UDP_In_Port = 9000;  //udp port input for ESP
 
-//default address and port to send to (IP read from config)
-IPAddress UKI_UDP_Out_IP ;
-int UKI_UDP_Out_Port = 8000 ;
 
-Ticker tkUKI;  // periodic send ADC to UDP
+//Ticker tkUKI;  // periodic send ADC to UDP
 int GSR_sensor;
 bool flag_UDP;
 int  UDP_tick = 50 ; //delay between to udp send
@@ -24,21 +19,22 @@ void UDP_send_receive() {
       
        /*  UKI part  */
     GSR_sensor = analogRead(A0);
-    //UKI_UDP.beginPacketMulticast((224, 1, 2, 3), 8000, WiFi.localIP());//
-    UKI_UDP.beginPacket(UKI_UDP_Out_IP, UKI_UDP_Out_Port);
-    UKI_UDP.print(UKI_NAME);
-    UKI_UDP.print(" ");
-    UKI_UDP.print(GSR_sensor);
-    UKI_UDP.endPacket();
+    IPAddress ipMulti(239, 0, 0, 57);
+    UDP.beginPacketMulticast( ipMulti, 12345, WiFi.localIP() );//
+    //UDP.beginPacket(UDP_Out_IP, UDP_Out_Port);
+    UDP.print(ESP_NAME);
+    UDP.print(" ");
+    UDP.print(GSR_sensor);
+    UDP.endPacket();
       
     //Check udp in
-    int packetSize = UKI_UDP.parsePacket();
+    int packetSize = UDP.parsePacket();
     
     if(packetSize) {
-      UKI_UDP_Out_IP = UKI_UDP.remoteIP();
-      UKI_UDP.beginPacket(UKI_UDP_Out_IP, 8000);
-      UKI_UDP.print("new master ip");
-      UKI_UDP.endPacket();
+      UDP_Out_IP = UDP.remoteIP();
+      UDP.beginPacket(UDP_Out_IP, 8000);
+      UDP.print("new master ip");
+      UDP.endPacket();
     }
     redLedState (0, 300);
   }
@@ -49,9 +45,9 @@ void UDP_send_receive() {
 
 
 void setupUDP(){
-  UKI_UDP_Out_IP.fromString(UKI_UDP_IP);
+  UDP_Out_IP.fromString(UDP_IP);
   Serial.print ("sending UDP to ");
-  Serial.println (UKI_UDP_Out_IP);
-  UKI_UDP.begin(UKI_UDP_In_Port); 
-  tkUKI.attach_ms(UDP_tick, UDP_flag); //raises flag 
+  Serial.println (UDP_Out_IP);
+  UDP.begin(UDP_In_Port); 
+  //tkUKI.attach_ms(UDP_tick, UDP_flag); //raises flag 
 }

+ 36 - 21
wifimgr.h

@@ -1,3 +1,18 @@
+#include <FS.h>                   //this needs to be first, or it all crashes and burns...
+
+#include <ESP8266WiFi.h>
+
+//web config portal
+#include <ESP8266WebServer.h>
+#include <DNSServer.h>
+#include <WiFiManager.h>
+
+//Configuration saving
+#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson
+
+
+
+
 //ticker flag for saving data
 bool flag_SaveConfig = false;
 
@@ -6,9 +21,9 @@ Ticker tkConfig ;
 bool flag_ConfigPortal = false;
 int timeout = 30000;
 
-char UKI_NAME[40];
-char UKI_UDP_PORT[6] = "9000";
-char UKI_UDP_IP[16] = "192.168.10.100";
+char ESP_NAME[40];
+char UDP_PORT[6] = "9000";
+char UDP_IP[16] = "192.168.10.100";
 
 
 
@@ -50,9 +65,9 @@ void ReadConfig() {
         if (json.success()) {
           Serial.println("\nparsed json");
 
-          strcpy(UKI_NAME, json["UKI_NAME"]);
-          strcpy(UKI_UDP_PORT, json["UKI_UDP_PORT"]);
-          strcpy(UKI_UDP_IP, json["UKI_UDP_IP"]);
+          strcpy(ESP_NAME, json["ESP_NAME"]);
+          strcpy(UDP_PORT, json["UDP_PORT"]);
+          strcpy(UDP_IP, json["UDP_IP"]);
           
 
         } 
@@ -76,9 +91,9 @@ void WriteConfig() {
       Serial.println("saving config");
       DynamicJsonBuffer jsonBuffer;
       JsonObject& json = jsonBuffer.createObject();
-      json["UKI_NAME"] = UKI_NAME;
-      json["UKI_UDP_PORT"] = UKI_UDP_PORT;
-      json["UKI_UDP_IP"] = UKI_UDP_IP;
+      json["ESP_NAME"] = ESP_NAME;
+      json["UDP_PORT"] = UDP_PORT;
+      json["UDP_IP"] = UDP_IP;
 
       File configFile = SPIFFS.open("/config.json", "w");
       if (!configFile) {
@@ -103,7 +118,7 @@ void StartConfigAP(){
     
     flag_ConfigPortal = false; //reset flag
     
-    // detach all tickers (redLed, blueLed, OTA, wifimgr, UKI_UDP)
+    // detach all tickers (redLed, blueLed, OTA, wifimgr, UDP)
     redLedState (1, 500);
     blueLedState (1,500);
     detachOTA();
@@ -117,9 +132,9 @@ void StartConfigAP(){
     // The extra parameters to be configured (can be either global or just in the setup)
     // After connecting, parameter.getValue() will get you the configured value
     // id/name placeholder/prompt default length
-    WiFiManagerParameter custom_UKI_NAME("name", "UKI NAME", UKI_NAME, 40);
-    WiFiManagerParameter custom_UKI_UDP_PORT("port", "UKI udp port", UKI_UDP_PORT, 5);
-    WiFiManagerParameter custom_UKI_UDP_IP("ip", "UKI udp IP", UKI_UDP_IP, 32);
+    WiFiManagerParameter custom_ESP_NAME("name", "ESP NAME", ESP_NAME, 40);
+    WiFiManagerParameter custom_UDP_PORT("port", " UDP port", UDP_PORT, 5);
+    WiFiManagerParameter custom_UDP_IP("ip", "UDP IP", UDP_IP, 32);
   
     //Local intialization. Once its business is done, there is no need to keep it around
     WiFiManager wifiManager;
@@ -128,9 +143,9 @@ void StartConfigAP(){
     wifiManager.setSaveConfigCallback(saveConfigCallback);//set config save notify callback
 
     //add all your parameters here
-    wifiManager.addParameter(&custom_UKI_NAME);
-    wifiManager.addParameter(&custom_UKI_UDP_PORT);
-    wifiManager.addParameter(&custom_UKI_UDP_IP);
+    wifiManager.addParameter(&custom_ESP_NAME);
+    wifiManager.addParameter(&custom_UDP_PORT);
+    wifiManager.addParameter(&custom_UDP_IP);
 
     //it starts an access point with the specified name
     //here  "AutoConnectAP"
@@ -144,7 +159,7 @@ void StartConfigAP(){
     //while (!flag_connected) {
       redLedState (1, 100);
       blueLedState (-1, 100);
-      if (!wifiManager.startConfigPortal(UKI_NAME)) {
+      if (!wifiManager.startConfigPortal(ESP_NAME)) {
         Serial.println("failed to connect, restarting config portal");
         delay(2000);
         //reset and try again
@@ -158,13 +173,13 @@ void StartConfigAP(){
 
 
     //if you get here you have connected to the WiFi
-    Serial.println("connected to UKI wifi");
+    Serial.println("connected to wifi");
     blueLedState(0,500);
 
     //read updated parameters
-    strcpy(UKI_NAME, custom_UKI_NAME.getValue());
-    strcpy(UKI_UDP_PORT, custom_UKI_UDP_PORT.getValue());
-    strcpy(UKI_UDP_IP, custom_UKI_UDP_IP.getValue());
+    strcpy(ESP_NAME, custom_ESP_NAME.getValue());
+    strcpy(UDP_PORT, custom_UDP_PORT.getValue());
+    strcpy(UDP_IP, custom_UDP_IP.getValue());
 
     WriteConfig();
     Serial.println("Restarting");