Liu Song’s Projects


~/Projects/AWTRIX2.0-Controller

git clone https://code.lsong.org/AWTRIX2.0-Controller

Commit

Commit
2fc06def1f2f8344cedd1e3a24a126db85dca675
Author
Stephan Mühl <31169771+[email protected]>
Date
2020-02-12 14:02:57 +0100 +0100
Diffstat
 src/AWTRIXController.cpp | 73 +++++++++++++++++++++--------------------

Merge pull request #16 from oliboehm/beta

Configuring different port in client


diff --git a/src/AWTRIXController.cpp b/src/AWTRIXController.cpp
index 4dc10c80b252c71a5c6649f099073322bc582045..09fabd18b591dc717994a5ceb4fa4fbed7ec3262 100644
--- a/src/AWTRIXController.cpp
+++ b/src/AWTRIXController.cpp
@@ -18,12 +18,15 @@ #include 
 #include <Wire.h>
 #include <SparkFun_APDS9960.h>
 #include "SoftwareSerial.h"
+
 #include <WiFiManager.h>
 #include <DoubleResetDetect.h>
 #include <Wire.h>
 #include <BME280_t.h>
 #include "Adafruit_HTU21DF.h"
+
 #include "DFRobotDFPlayerMini.h"
+
 #include "MenueControl/MenueControl.h"
 
 // instantiate temp sensor
@@ -39,10 +42,10 @@
 bool MatrixType2 = false;
 int matrixTempCorrection = 0;
 
-String version = "0.21";
+String version = "0.21 Custom";
-// by Blueforcer & Mazze2000
 #include <ESP8266WebServer.h>
+#include "MenueControl/MenueControl.h"
-
+char Port[5] = "7001";          // AWTRIX Host Port, default = 7001
 IPAddress Server;
 WiFiClient espClient;
 PubSubClient client(espClient);
@@ -161,13 +164,14 @@ 	JsonObject &json = jsonBuffer.createObject();
 	json["awtrix_server"] = awtrix_server;
 	json["MatrixType"] = MatrixType2;
 	json["matrixCorrection"] = matrixTempCorrection;
+	json["Port"] = Port;
 
 	//json["temp"] = tempState;
 	//json["usbWifi"] = USBConnection;
 	//json["ldr"] = ldrState;
 	//json["gesture"] = gestureState;
 	//json["audio"] = audioState;
-	
+
 	File configFile = SPIFFS.open("/awtrix.json", "w");
 	if (!configFile)
 	{
@@ -894,7 +898,6 @@ 		{
 			//Command 17: Volume
 			myMP3.volume(payload[1]);
 
-bool allowTasterSendToServer = true;
 			break;
 		}
 		case 18:
@@ -1031,7 +1034,7 @@ }
 
 void configModeCallback(WiFiManager *myWiFiManager)
 {
-	
+
 	if (!USBConnection)
 	{
 		Serial.println("Entered config mode");
@@ -1043,7 +1046,7 @@ 	matrix->setCursor(3, 6);
 	matrix->setTextColor(matrix->Color(0, 255, 50));
 	matrix->print("Hotspot");
 	matrix->show();
-	
+
 }
 
 void setup()
@@ -1053,7 +1056,7 @@ 	Serial.setRxBufferSize(1024);
 	Serial.begin(115200);
 	mySoftwareSerial.begin(9600);
 
-	
+
 
 	if (SPIFFS.begin())
 	{
@@ -1074,7 +1077,7 @@ 			DynamicJsonBuffer jsonBuffer;
 			JsonObject &json = jsonBuffer.parseObject(buf.get());
 			if (json.success())
 			{
-				
+
 				strcpy(awtrix_server, json["awtrix_server"]);
 				//USBConnection = json["usbWifi"].as<bool>();
 				//audioState = json["audio"].as<int>();
@@ -1083,6 +1086,7 @@ 				//ldrState = json["ldr"].as();
 				//tempState = json["temp"].as<int>();
 				MatrixType2 = json["MatrixType"].as<bool>();
 				matrixTempCorrection = json["matrixCorrection"].as<int>();
+				strcpy(Port, json["Port"]);
 			}
 			configFile.close();
 		}
@@ -1092,7 +1096,7 @@ 	{
 		//error
 	}
 
-	
+
 	Serial.println("Matrix Type");
 
 	if (!MatrixType2)
@@ -1193,7 +1197,6 @@ 		{
 			delay(1000);
 			SPIFFS.remove("/awtrix.json");
 
-bool allowTasterSendToServer = true;
 			SPIFFS.end();
 			delay(1000);
 		}
@@ -1201,17 +1204,16 @@ 		wifiManager.resetSettings();
 		ESP.reset();
 	}
 
-	
+
 	wifiManager.setAPStaticIPConfig(IPAddress(172, 217, 28, 1), IPAddress(172, 217, 28, 1), IPAddress(255, 255, 255, 0));
 	WiFiManagerParameter custom_awtrix_server("server", "AWTRIX Host", awtrix_server, 16);
-#include <ArduinoOTA.h>
+#include <ESP8266WebServer.h>
 // by Blueforcer & Mazze2000
-#include <ESP8266httpUpdate.h>
-// AWTRIX Controller
+#include <ArduinoOTA.h>
 // by Blueforcer & Mazze2000
-#include <ESP8266WiFi.h>
+#include <ESP8266httpUpdate.h>
 	// Just a quick hint
-bool pushed[] = {false, false, false, false};
+#define LDR_RESISTOR 1000 //ohms
 // AWTRIX Controller
 	WiFiManagerParameter p_lineBreak_notext("<p></p>");
 
@@ -1221,23 +1222,24 @@
 	wifiManager.addParameter(&custom_awtrix_server);
 	wifiManager.addParameter(&p_lineBreak_notext);
 	wifiManager.addParameter(&p_MatrixType2);
+	wifiManager.addParameter(&custom_port);
 
 	wifiManager.addParameter(&p_lineBreak_notext);
  	//wifiManager.setCustomHeadElement("<style>html{ background-color: #607D8B;}</style>");
-	
+
 	hardwareAnimatedSearch(0, 24, 0);
 
-	
+
 	if (!wifiManager.autoConnect("AWTRIX Controller", "awtrixxx"))
 	{
 		//reset and try again, or maybe put it to deep sleep
 		ESP.reset();
 		delay(5000);
 	}
-	
+
 	//is needed for only one hotpsot!
 	WiFi.mode(WIFI_STA);
-	
+
 	server.on("/", HTTP_GET, []() {
 		server.sendHeader("Connection", "close");
 		server.send(200, "text/html", serverIndex);
@@ -1247,11 +1249,10 @@       server.sendHeader("Connection", "close");
       server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
       ESP.restart(); }, []() {
       HTTPUpload& upload = server.upload();
-bool blockTaster[] = {false, false, false, false};
 
       if (upload.status == UPLOAD_FILE_START) {
         Serial.setDebugOutput(true);
-		
+
         uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
         if (!Update.begin(maxSketchSpace)) { //start with max available size
           Update.printError(Serial);
@@ -1265,8 +1266,8 @@         }
       } else if (upload.status == UPLOAD_FILE_END) {
         if (Update.end(true)) { //true to set the size to the current progress
 		  server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
-		  
+
-          
+
         } else {
           Update.printError(Serial);
         }
@@ -1275,20 +1276,21 @@       }
       yield(); });
 
 	server.begin();
-	
+
-	
+
-	
+
-	
+
 	if (shouldSaveConfig)
 	{
-		
+
 		strcpy(awtrix_server, custom_awtrix_server.getValue());
 		MatrixType2 = (strncmp(p_MatrixType2.getValue(), "T", 1) == 0);
+		strcpy(Port, custom_port.getValue());
 		//USBConnection = (strncmp(p_USBConnection.getValue(), "T", 1) == 0);
 		saveConfig();
 		ESP.reset();
 	}
-	
+
 
 	hardwareAnimatedCheck(0, 27, 2);
 
@@ -1297,7 +1299,7 @@
 	//Checking periphery
 	Wire.begin(I2C_SDA, I2C_SCL);
 	if (BMESensor.begin())
-	{	
+	{
 		//temp OK
 		tempState = 1;
 		hardwareAnimatedCheck(2, 29, 2);
@@ -1337,7 +1339,7 @@ 		flashProgress(progress, total);
 	});
 
 	ArduinoOTA.begin();
-	
+
 	matrix->clear();
 	matrix->setCursor(7, 6);
 
@@ -1353,13 +1355,13 @@ 	for (int x = 32; x >= -90; x--)
 	{
 		matrix->clear();
 		matrix->setCursor(x, 6);
-		matrix->print("Host-IP: " + String(awtrix_server));
+		matrix->print("Host-IP: " + String(awtrix_server) + ":" + String(Port));
 		matrix->setTextColor(matrix->Color(0, 255, 50));
 		matrix->show();
 		delay(40);
 	}
 
-	client.setServer(awtrix_server, 7001);
+	client.setServer(awtrix_server, atoi(Port));
 	client.setCallback(callback);
 
 	pinMode(D0, INPUT);