LCD and EmonCMS support

LCD and EmonCMS support
This commit is contained in:
mvdbro
2015-10-11 14:09:06 +02:00
parent 84a34019d3
commit 6825508081
5 changed files with 198 additions and 12 deletions
+1 -1
View File
@@ -79,7 +79,7 @@
#define ESP_PROJECT_PID 2015050101L
#define ESP_EASY
#define VERSION 9
#define BUILD 34
#define BUILD 35
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
#define FEATURE_SPIFFS false
+31
View File
@@ -213,6 +213,37 @@ void LoadTaskSettings(byte TaskIndex)
#endif
}
/********************************************************************************************\
* Save Custom Task settings to SPIFFS
\*********************************************************************************************/
void SaveCustomTaskSettings(int TaskIndex, byte* memAddress, int datasize)
{
if (datasize > 512)
return;
#if FEATURE_SPIFFS
SaveToFile((char*)"config.txt", 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
#else
SaveToFlash(4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
#endif
}
/********************************************************************************************\
* Save Custom Task settings to SPIFFS
\*********************************************************************************************/
void LoadCustomTaskSettings(int TaskIndex, byte* memAddress, int datasize)
{
if (datasize > 512)
return;
#if FEATURE_SPIFFS
LoadFromFile((char*)"config.txt", 4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
#else
LoadFromFlash(4096 + (TaskIndex * 1024) + 512, memAddress, datasize);
#endif
}
#if FEATURE_SPIFFS
/********************************************************************************************\
* Save data into config file on SPIFFS
+1 -11
View File
@@ -1,5 +1,5 @@
//#######################################################################################################
//########################### Controller Plugin 007: Emoncms ###########################################
//########################### Controller Plugin 007: Emoncms ############################################
//#######################################################################################################
#define CPLUGIN_007
@@ -107,17 +107,7 @@ boolean CPlugin_007(byte function, struct EventStruct *event)
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
{
sprintf_P(log, PSTR("C1 WS %u FM %u"), WiFi.status(), FreeMem());
Serial.println(log);
}
String line = client.readStringUntil('\n');
if (Settings.SerialLogLevel >= LOG_LEVEL_DEBUG_MORE)
{
sprintf_P(log, PSTR("C2 WS %u FM %u"), WiFi.status(), FreeMem());
Serial.println(log);
}
line.toCharArray(log, 80);
addLog(LOG_LEVEL_DEBUG_MORE, log);
if (line.substring(0, 15) == "HTTP/1.1 200 OK")
+161
View File
@@ -0,0 +1,161 @@
//#######################################################################################################
//#################################### Plugin 012: LCD ##################################################
//#######################################################################################################
// Sample templates
// Temp: [DHT11#Temperature] Hum:[DHT11#humidity]
// DS Temp:[Dallas1#Temperature#R]
// Lux:[Lux#Lux#R]
// Baro:[Baro#Pressure#R]
#define PLUGIN_012
#define PLUGIN_ID_012 12
#define PLUGIN_NAME_012 "LCD Display"
#define PLUGIN_VALUENAME1_012 "LCD"
boolean Plugin_012(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_012;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 0;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_012);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_012));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
char deviceTemplate[4][80];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
for (byte varNr = 0; varNr < 4; varNr++)
{
string += F("<TR><TD>Line ");
string += varNr + 1;
string += F(":<TD><input type='text' size='80' maxlength='80' name='Plugin_012_template");
string += varNr + 1;
string += F("' value='");
string += deviceTemplate[varNr];
string += F("'>");
}
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
char deviceTemplate[4][80];
for (byte varNr = 0; varNr < 4; varNr++)
{
char argc[25];
String arg = "Plugin_012_template";
arg += varNr + 1;
arg.toCharArray(argc, 25);
String tmpString = WebServer.arg(argc);
char tmp[81];
tmpString.toCharArray(tmp, 81);
urlDecode(tmp);
strcpy(deviceTemplate[varNr], tmp);
}
Settings.TaskDeviceID[event->TaskIndex] = 1; // temp fix, needs a dummy value
SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
success = true;
break;
}
case PLUGIN_READ:
{
char deviceTemplate[4][80];
LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemplate, sizeof(deviceTemplate));
for (byte x = 0; x < 4; x++)
{
String newString = "";
String tmpString = deviceTemplate[x];
String tmpStringMid = "";
int leftBracketIndex = tmpString.indexOf('[');
if (leftBracketIndex == -1)
newString = tmpString;
byte count = 0;
while (leftBracketIndex >= 0 && count < 10 - 1)
{
newString += tmpString.substring(0, leftBracketIndex);
tmpString = tmpString.substring(leftBracketIndex + 1);
int rightBracketIndex = tmpString.indexOf(']');
if (rightBracketIndex)
{
tmpStringMid = tmpString.substring(0, rightBracketIndex);
tmpString = tmpString.substring(rightBracketIndex + 1);
int hashtagIndex = tmpStringMid.indexOf('#');
String deviceName = tmpStringMid.substring(0, hashtagIndex);
String valueName = tmpStringMid.substring(hashtagIndex + 1);
String valueFormat = "";
hashtagIndex = valueName.indexOf('#');
if (hashtagIndex >= 0)
{
valueFormat = valueName.substring(hashtagIndex + 1);
valueName = valueName.substring(0, hashtagIndex);
}
for (byte y = 0; y < TASKS_MAX; y++)
{
LoadTaskSettings(y);
if (ExtraTaskSettings.TaskDeviceName[0] != 0)
{
if (deviceName.equalsIgnoreCase(ExtraTaskSettings.TaskDeviceName))
{
for (byte z = 0; z < VARS_PER_TASK; z++)
if (valueName.equalsIgnoreCase(ExtraTaskSettings.TaskDeviceValueNames[z]))
{
// here we know the task and value, so find the uservar
String value = String(UserVar[y * VARS_PER_TASK + z]);
if (valueFormat == "R")
{
int filler = 20 - newString.length() - value.length() - tmpString.length() ;
for (byte f = 0; f < filler; f++)
newString += " ";
}
newString += String(value);
}
}
}
}
}
leftBracketIndex = tmpString.indexOf('[');
count++;
}
newString += tmpString;
//Serial.print("LCD : ");
//Serial.println(newString);
lcd.setCursor(0, x);
lcd.print(newString);
}
success = false;
break;
}
}
return success;
}
+4
View File
@@ -1,3 +1,7 @@
// R35 11-10-2015
// Finally finished the LCD plugin with some basic functionality
// Preliminary controller support for EmonCMS
// R34 10-10-2015
// Changed controller password length from 25 to 63 chars.
// If you have set a system password, it will be cleared with this update