fix commit

This commit is contained in:
esp8266nu
2015-09-08 15:01:11 +00:00
parent 22f6225b97
commit fd5120aaf2
14 changed files with 1874 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
//#######################################################################################################
//#################################### Plugin 001: Input Switch #########################################
//#######################################################################################################
#define PLUGIN_001
#define PLUGIN_ID_001 1
boolean Plugin_001(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte switchstate[TASKS_MAX];
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_001;
strcpy(Device[deviceCount].Name, "Switch input");
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = 10;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = true;
Device[deviceCount].InverseLogicOption = true;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Switch");
break;
}
case PLUGIN_INIT:
{
if (Settings.TaskDevicePin1PullUp[event->TaskIndex])
{
Serial.print(F("INIT : InputPullup "));
pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
}
else
{
Serial.print(F("INIT : Input "));
pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT);
}
switchstate[event->TaskIndex] = digitalRead(Settings.TaskDevicePin1[event->TaskIndex]);
success = true;
break;
}
case PLUGIN_TEN_PER_SECOND:
{
byte state = digitalRead(Settings.TaskDevicePin1[event->TaskIndex]);
if (state != switchstate[event->TaskIndex])
{
Serial.print(F("SW : State "));
Serial.println(state);
switchstate[event->TaskIndex] = state;
if (Settings.TaskDevicePin1Inversed[event->TaskIndex])
state = !state;
UserVar[event->BaseVarIndex] = state;
sendData(event->TaskIndex, 10, Settings.TaskDeviceID[event->TaskIndex], event->BaseVarIndex);
}
success = true;
break;
}
}
return success;
}
+41
View File
@@ -0,0 +1,41 @@
//#######################################################################################################
//#################################### Plugin 002: Analog ###############################################
//#######################################################################################################
#define PLUGIN_002
#define PLUGIN_ID_002 2
boolean Plugin_002(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_002;
strcpy(Device[deviceCount].Name, "Analog input");
Device[deviceCount].Type = DEVICE_TYPE_ANALOG;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Analog");
break;
}
case PLUGIN_COMMAND:
{
int value = analogRead(A0);
UserVar[event->BaseVarIndex] = (float)value;
Serial.print("ADC : Analog value: ");
Serial.println(value);
success = true;
break;
}
}
return success;
}
+140
View File
@@ -0,0 +1,140 @@
//#######################################################################################################
//#################################### Plugin 003: Pulse ###############################################
//#######################################################################################################
#define PLUGIN_003
#define PLUGIN_ID_003 3
unsigned long Plugin_003_pulseCounter[TASKS_MAX];
unsigned long Plugin_003_pulseTotalCounter[TASKS_MAX];
boolean Plugin_003(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_003;
strcpy(Device[deviceCount].Name, "Pulse Counter");
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Count");
break;
}
case PLUGIN_WEBFORM_VALUES:
{
string += F("<TD>");
string += Plugin_003_pulseCounter[event->TaskIndex];
string += F("<TD>");
string += Plugin_003_pulseTotalCounter[event->TaskIndex];
success = true;
break;
}
case PLUGIN_INIT:
{
Serial.print(F("INIT : Pulse "));
Serial.println(Settings.TaskDevicePin1[event->TaskIndex]);
pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
Plugin_003_pulseinit(Settings.TaskDevicePin1[event->TaskIndex], event->TaskIndex);
success = true;
break;
}
case PLUGIN_COMMAND:
{
UserVar[event->BaseVarIndex] = Plugin_003_pulseCounter[event->TaskIndex];
Plugin_003_pulseCounter[event->TaskIndex] = 0;
success = true;
break;
}
}
return success;
}
/*********************************************************************************************\
* Pulse Counters
\*********************************************************************************************/
void Plugin_003_pulse_interrupt1()
{
Plugin_003_pulseCounter[0]++;
Plugin_003_pulseTotalCounter[0]++;
}
void Plugin_003_pulse_interrupt2()
{
Plugin_003_pulseCounter[1]++;
Plugin_003_pulseTotalCounter[1]++;
}
void Plugin_003_pulse_interrupt3()
{
Plugin_003_pulseCounter[2]++;
Plugin_003_pulseTotalCounter[2]++;
}
void Plugin_003_pulse_interrupt4()
{
Plugin_003_pulseCounter[3]++;
Plugin_003_pulseTotalCounter[3]++;
}
void Plugin_003_pulse_interrupt5()
{
Plugin_003_pulseCounter[4]++;
Plugin_003_pulseTotalCounter[4]++;
}
void Plugin_003_pulse_interrupt6()
{
Plugin_003_pulseCounter[5]++;
Plugin_003_pulseTotalCounter[5]++;
}
void Plugin_003_pulse_interrupt7()
{
Plugin_003_pulseCounter[6]++;
Plugin_003_pulseTotalCounter[6]++;
}
void Plugin_003_pulse_interrupt8()
{
Plugin_003_pulseCounter[7]++;
Plugin_003_pulseTotalCounter[7]++;
}
void Plugin_003_pulseinit(byte Par1, byte Index)
{
// Init IO pins
Serial.println("PULSE: Init");
switch (Index)
{
case 0:
attachInterrupt(Par1, Plugin_003_pulse_interrupt1, FALLING);
break;
case 1:
attachInterrupt(Par1, Plugin_003_pulse_interrupt2, FALLING);
break;
case 2:
attachInterrupt(Par1, Plugin_003_pulse_interrupt3, FALLING);
break;
case 3:
attachInterrupt(Par1, Plugin_003_pulse_interrupt4, FALLING);
break;
case 4:
attachInterrupt(Par1, Plugin_003_pulse_interrupt5, FALLING);
break;
case 5:
attachInterrupt(Par1, Plugin_003_pulse_interrupt6, FALLING);
break;
case 6:
attachInterrupt(Par1, Plugin_003_pulse_interrupt7, FALLING);
break;
case 7:
attachInterrupt(Par1, Plugin_003_pulse_interrupt8, FALLING);
break;
}
}
+143
View File
@@ -0,0 +1,143 @@
//#######################################################################################################
//#################################### Plugin 004: TempSensor Dallas DS18B20 ###########################
//#######################################################################################################
#define PLUGIN_004
#define PLUGIN_ID_004 4
uint8_t Plugin_004_DallasPin;
boolean Plugin_004(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static unsigned int Call_Status = 0x00; // Each bit represents one relative port. 0=not called before, 1=already called before.
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_004;
strcpy(Device[deviceCount].Name, "Temperature DS18b20");
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Temperature");
break;
}
case PLUGIN_COMMAND:
{
int DSTemp; // Temperature in 16-bit Dallas format.
byte ScratchPad[12]; // Scratchpad buffer Dallas sensor.
byte RelativePort = Settings.TaskDevicePin1[event->TaskIndex];
Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex];
noInterrupts();
while (!(bitRead(Call_Status, RelativePort)))
{
// if this is the very first call to the sensor on this port, reset it to wake it up
boolean present = Plugin_004_DS_reset();
bitSet(Call_Status, RelativePort);
}
boolean present = Plugin_004_DS_reset(); Plugin_004_DS_write(0xCC /* rom skip */); Plugin_004_DS_write(0x44 /* start conversion */);
interrupts();
if (present)
{
delay(800); // neccesary delay
noInterrupts();
Plugin_004_DS_reset(); Plugin_004_DS_write(0xCC /* rom skip */); Plugin_004_DS_write(0xBE /* Read Scratchpad */);
digitalWrite(Plugin_004_DallasPin, LOW);
pinMode(Plugin_004_DallasPin, INPUT);
for (byte i = 0; i < 9; i++) // copy 8 bytes
ScratchPad[i] = Plugin_004_DS_read();
interrupts();
DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];
UserVar[event->BaseVarIndex] = (float(DSTemp) * 0.0625);
Serial.print("DS : Temperature: ");
Serial.println(UserVar[event->BaseVarIndex]);
success = true;
}
break;
}
}
return success;
}
uint8_t Plugin_004_DS_read(void)
{
uint8_t bitMask;
uint8_t r = 0;
uint8_t BitRead;
for (bitMask = 0x01; bitMask; bitMask <<= 1)
{
pinMode(Plugin_004_DallasPin, OUTPUT);
digitalWrite(Plugin_004_DallasPin, LOW);
delayMicroseconds(3);
pinMode(Plugin_004_DallasPin, INPUT); // let pin float, pull up will raise
delayMicroseconds(10);
BitRead = digitalRead(Plugin_004_DallasPin);
delayMicroseconds(53);
if (BitRead)
r |= bitMask;
}
return r;
}
void Plugin_004_DS_write(uint8_t ByteToWrite)
{
uint8_t bitMask;
pinMode(Plugin_004_DallasPin, OUTPUT);
for (bitMask = 0x01; bitMask; bitMask <<= 1)
{ // BitWrite
digitalWrite(Plugin_004_DallasPin, LOW);
if (((bitMask & ByteToWrite) ? 1 : 0) & 1)
{
delayMicroseconds(5);// Dallas spec.= 5..15 uSec.
digitalWrite(Plugin_004_DallasPin, HIGH);
delayMicroseconds(55);// Dallas spec.= 60uSec.
}
else
{
delayMicroseconds(55);// Dallas spec.= 60uSec.
digitalWrite(Plugin_004_DallasPin, HIGH);
delayMicroseconds(5);// Dallas spec.= 5..15 uSec.
}
}
}
uint8_t Plugin_004_DS_reset()
{
uint8_t r;
uint8_t retries = 125;
pinMode(Plugin_004_DallasPin, INPUT);
do { // wait until the wire is high... just in case
if (--retries == 0) return 0;
delayMicroseconds(2);
} while ( !digitalRead(Plugin_004_DallasPin));
pinMode(Plugin_004_DallasPin, OUTPUT); digitalWrite(Plugin_004_DallasPin, LOW);
delayMicroseconds(492); // Dallas spec. = Min. 480uSec. Arduino 500uSec.
pinMode(Plugin_004_DallasPin, INPUT); //Float
delayMicroseconds(40);
r = !digitalRead(Plugin_004_DallasPin);
delayMicroseconds(420);
return r;
}
+194
View File
@@ -0,0 +1,194 @@
//#######################################################################################################
//######################## Plugin 006: Temperature and Humidity sensor DHT 11/22 ########################
//#######################################################################################################
#define PLUGIN_005
#define PLUGIN_ID_005 5
uint8_t Plugin_005_DHT_Pin;
boolean Plugin_005(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_005;
strcpy(Device[deviceCount].Name, "Temp + Hum DHT");
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = 2;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 2;
strcpy(Device[deviceCount].ValueNames[0], "Temperature");
strcpy(Device[deviceCount].ValueNames[1], "Humidity");
break;
}
case PLUGIN_WEBFORM_LOAD:
{
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
String options[2];
options[0] = F("DHT 11");
options[1] = F("DHT 22");
int optionValues[2];
optionValues[0] = 11;
optionValues[1] = 22;
string += F("<TR><TD>DHT Type:<TD><select name='plugin1'>");
for (byte x = 0; x < 2; x++)
{
string += F("<option value='");
string += optionValues[x];
string += "'";
if (choice == optionValues[x])
string += " selected";
string += ">";
string += options[x];
string += "</option>";
}
string += F("</select>");
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
String plugin1 = WebServer.arg("plugin1");
Settings.TaskDevicePluginConfig[event->TaskIndex][0] = plugin1.toInt();
success = true;
break;
}
case PLUGIN_COMMAND:
{
byte dht_dat[5];
byte dht_in;
byte i;
byte Retry = 0;
boolean error = false;
byte Par3 = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
Plugin_005_DHT_Pin = Settings.TaskDevicePin1[event->TaskIndex];
do
{
pinMode(Plugin_005_DHT_Pin, OUTPUT);
// DHT start condition, pull-down i/o pin for 18ms
digitalWrite(Plugin_005_DHT_Pin, LOW); // Pull low
delay(18);
digitalWrite(Plugin_005_DHT_Pin, HIGH); // Pull high
delayMicroseconds(40);
pinMode(Plugin_005_DHT_Pin, INPUT); // change pin to input
//delayMicroseconds(40);
dht_in = digitalRead(Plugin_005_DHT_Pin);
if (!dht_in)
{
delayMicroseconds(80);
dht_in = digitalRead(Plugin_005_DHT_Pin);
if (dht_in)
{
delayMicroseconds(40); // now ready for data reception
for (i = 0; i < 5; i++)
{
byte data = Plugin_005_read_dht_dat();
if (data != -1)
dht_dat[i] = data;
else
{
addLog(LOG_LEVEL_ERROR, (char*)"DHT : protocol timeout!");
error = true;
}
}
if (!error)
{
// Checksum calculation is a Rollover Checksum by design!
byte dht_check_sum = dht_dat[0] + dht_dat[1] + dht_dat[2] + dht_dat[3]; // check check_sum
if (dht_dat[4] == dht_check_sum)
{
if (Par3 == 11)
{
UserVar[event->BaseVarIndex] = float(dht_dat[2]); // Temperature
UserVar[event->BaseVarIndex + 1] = float(dht_dat[0]); // Humidity
}
if (Par3 == 22)
{
if (dht_dat[2] & 0x80) // negative temperature
UserVar[event->BaseVarIndex] = -0.1 * word(dht_dat[2] & 0x7F, dht_dat[3]);
else
UserVar[event->BaseVarIndex] = 0.1 * word(dht_dat[2], dht_dat[3]);
UserVar[event->BaseVarIndex + 1] = word(dht_dat[0], dht_dat[1]) * 0.1; // Humidity
}
Serial.print("DHT : Temperature: ");
Serial.println(UserVar[event->BaseVarIndex]);
Serial.print("DHT : Humidity: ");
Serial.println(UserVar[event->BaseVarIndex + 1]);
success = true;
} // checksum
} // error
} // dht
} // !dht
if (!success)
{
delay(2000);
}
} while (!success && ++Retry < 3);
break;
}
}
return success;
}
/*********************************************************************************************\
* DHT sub to get an 8 bit value from the receiving bitstream
\*********************************************************************************************/
int Plugin_005_read_dht_dat(void)
{
byte i = 0;
byte result = 0;
byte counter = 0;
noInterrupts();
for (i = 0; i < 8; i++)
{
while ((!digitalRead(Plugin_005_DHT_Pin)) && (counter < 100))
{
delayMicroseconds(1);
counter++;
}
if (counter >= 100)
{
interrupts();
return -1;
}
delayMicroseconds(30);
if (digitalRead(Plugin_005_DHT_Pin))
result |= (1 << (7 - i));
counter = 0;
while ((digitalRead(Plugin_005_DHT_Pin)) && (counter < 100))
{
delayMicroseconds(1);
counter++;
}
if (counter >= 100)
{
interrupts();
return -1;
}
}
interrupts();
return result;
}
+235
View File
@@ -0,0 +1,235 @@
//#######################################################################################################
//######################## Plugin 006 BMP0685 I2C Barometric Pressure Sensor ###########################
//#######################################################################################################
#define PLUGIN_006
#define PLUGIN_ID_006 6
boolean Plugin_006_init = false;
boolean Plugin_006(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_006;
strcpy(Device[deviceCount].Name, "Temp + Baro BMP085");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 3;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 2;
strcpy(Device[deviceCount].ValueNames[0], "Temperature");
strcpy(Device[deviceCount].ValueNames[1], "Pressure");
break;
}
case PLUGIN_COMMAND:
{
if (!Plugin_006_init)
{
Plugin_006_init = true;
Serial.println("BMP init");
Plugin_006_bmp085_begin();
}
UserVar[event->BaseVarIndex] = Plugin_006_bmp085_readTemperature();
UserVar[event->BaseVarIndex + 1] = ((float)Plugin_006_bmp085_readPressure()) / 100;
Serial.print("BMP : Temperature: ");
Serial.println(UserVar[event->BaseVarIndex]);
Serial.print("BMP : Barometric Pressure: ");
Serial.println(UserVar[event->BaseVarIndex + 1]);
success = true;
break;
}
}
return success;
}
#define BMP085_I2CADDR 0x77
#define BMP085_ULTRAHIGHRES 3
#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
#define BMP085_CONTROL 0xF4
#define BMP085_TEMPDATA 0xF6
#define BMP085_PRESSUREDATA 0xF6
#define BMP085_READTEMPCMD 0x2E
#define BMP085_READPRESSURECMD 0x34
uint8_t oversampling = BMP085_ULTRAHIGHRES;
int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
uint16_t ac4, ac5, ac6;
/*********************************************************************/
boolean Plugin_006_bmp085_begin()
/*********************************************************************/
{
if (Plugin_006_bmp085_read8(0xD0) != 0x55) return false;
/* read calibration data */
ac1 = Plugin_006_bmp085_read16(BMP085_CAL_AC1);
ac2 = Plugin_006_bmp085_read16(BMP085_CAL_AC2);
ac3 = Plugin_006_bmp085_read16(BMP085_CAL_AC3);
ac4 = Plugin_006_bmp085_read16(BMP085_CAL_AC4);
ac5 = Plugin_006_bmp085_read16(BMP085_CAL_AC5);
ac6 = Plugin_006_bmp085_read16(BMP085_CAL_AC6);
b1 = Plugin_006_bmp085_read16(BMP085_CAL_B1);
b2 = Plugin_006_bmp085_read16(BMP085_CAL_B2);
mb = Plugin_006_bmp085_read16(BMP085_CAL_MB);
mc = Plugin_006_bmp085_read16(BMP085_CAL_MC);
md = Plugin_006_bmp085_read16(BMP085_CAL_MD);
}
/*********************************************************************/
uint16_t Plugin_006_bmp085_readRawTemperature(void)
/*********************************************************************/
{
Plugin_006_bmp085_write8(BMP085_CONTROL, BMP085_READTEMPCMD);
delay(5);
return Plugin_006_bmp085_read16(BMP085_TEMPDATA);
}
/*********************************************************************/
uint32_t Plugin_006_bmp085_readRawPressure(void)
/*********************************************************************/
{
uint32_t raw;
Plugin_006_bmp085_write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
delay(26);
raw = Plugin_006_bmp085_read16(BMP085_PRESSUREDATA);
raw <<= 8;
raw |= Plugin_006_bmp085_read8(BMP085_PRESSUREDATA + 2);
raw >>= (8 - oversampling);
return raw;
}
/*********************************************************************/
int32_t Plugin_006_bmp085_readPressure(void)
/*********************************************************************/
{
int32_t UT, UP, B3, B5, B6, X1, X2, X3, p;
uint32_t B4, B7;
UT = Plugin_006_bmp085_readRawTemperature();
UP = Plugin_006_bmp085_readRawPressure();
// do temperature calculations
X1 = (UT - (int32_t)(ac6)) * ((int32_t)(ac5)) / pow(2, 15);
X2 = ((int32_t)mc * pow(2, 11)) / (X1 + (int32_t)md);
B5 = X1 + X2;
// do pressure calcs
B6 = B5 - 4000;
X1 = ((int32_t)b2 * ( (B6 * B6) >> 12 )) >> 11;
X2 = ((int32_t)ac2 * B6) >> 11;
X3 = X1 + X2;
B3 = ((((int32_t)ac1 * 4 + X3) << oversampling) + 2) / 4;
X1 = ((int32_t)ac3 * B6) >> 13;
X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15;
B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling );
if (B7 < 0x80000000)
{
p = (B7 * 2) / B4;
}
else
{
p = (B7 / B4) * 2;
}
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
p = p + ((X1 + X2 + (int32_t)3791) >> 4);
return p;
}
/*********************************************************************/
float Plugin_006_bmp085_readTemperature(void)
/*********************************************************************/
{
int32_t UT, X1, X2, B5; // following ds convention
float temp;
UT = Plugin_006_bmp085_readRawTemperature();
// step 1
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2, 15);
X2 = ((int32_t)mc * pow(2, 11)) / (X1 + (int32_t)md);
B5 = X1 + X2;
temp = (B5 + 8) / pow(2, 4);
temp /= 10;
return temp;
}
/*********************************************************************/
uint8_t Plugin_006_bmp085_read8(uint8_t a)
/*********************************************************************/
{
uint8_t ret;
Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device
Wire.write(a); // sends register address to read from
Wire.endTransmission(); // end transmission
Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device
Wire.requestFrom(BMP085_I2CADDR, 1);// send data n-bytes read
ret = Wire.read(); // receive DATA
Wire.endTransmission(); // end transmission
return ret;
}
/*********************************************************************/
uint16_t Plugin_006_bmp085_read16(uint8_t a)
/*********************************************************************/
{
uint16_t ret;
Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device
Wire.write(a); // sends register address to read from
Wire.endTransmission(); // end transmission
Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device
Wire.requestFrom(BMP085_I2CADDR, 2);// send data n-bytes read
ret = Wire.read(); // receive DATA
ret <<= 8;
ret |= Wire.read(); // receive DATA
Wire.endTransmission(); // end transmission
return ret;
}
/*********************************************************************/
void Plugin_006_bmp085_write8(uint8_t a, uint8_t d)
/*********************************************************************/
{
Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device
Wire.write(a); // sends register address to read from
Wire.write(d); // write data
Wire.endTransmission(); // end transmission
}
+67
View File
@@ -0,0 +1,67 @@
//#######################################################################################################
//#################################### Plugin 007: ExtWiredAnalog #######################################
//#######################################################################################################
/*********************************************************************************************\
* This plugin provides support for 4 extra analog inputs, using the PCF8591 (NXP/Philips)
* Support : www.esp8266.nu
* Date : Apr 2015
* Compatibility : R004
* Syntax : "ExtWiredAnalog <Par1:Port>, <Par2:Variable>"
*********************************************************************************************
* Technical description:
*
* De PCF8591 is a IO Expander chip that connects through the I2C bus
* Basic I2C address = 0x48
* Each chip has 4 analog inputs
* This commando reads the analog input en stores the result into a variable
\*********************************************************************************************/
#define PLUGIN_007
#define PLUGIN_ID_007 7
boolean Plugin_007(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte portValue = 0;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_007;
strcpy(Device[deviceCount].Name, "PCF8591 Analog input");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 4;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Analog");
break;
}
case PLUGIN_COMMAND:
{
byte unit = (Settings.TaskDevicePort[event->TaskIndex] - 1) / 4;
byte port = Settings.TaskDevicePort[event->TaskIndex] - (unit * 4);
uint8_t address = 0x48 + unit;
// get the current pin value
Wire.beginTransmission(address);
Wire.write(port - 1);
Wire.endTransmission();
Wire.requestFrom(address, (uint8_t)0x2);
if (Wire.available())
{
Wire.read(); // Read older value first (stored in chip)
UserVar[event->BaseVarIndex] = (float)Wire.read(); // now read actual value and store into Nodo var
success = true;
}
break;
}
}
return success;
}
+103
View File
@@ -0,0 +1,103 @@
//#######################################################################################################
//################################# Plugin 008: Wiegand RFID Tag Reader #################################
//#######################################################################################################
#define PLUGIN_008
#define PLUGIN_ID_008 8
#define PLUGIN_008_WGSIZE 26
volatile byte Plugin_008_bitCount = 0; // Count the number of bits received.
volatile unsigned long Plugin_008_keyBuffer = 0; // A 32-bit-long keyBuffer into which the number is stored.
byte Plugin_008_bitCountPrev = 0; // to detect noise
byte Plugin_008_Unit = 0;
boolean Plugin_008_init = false;
boolean Plugin_008(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_008;
strcpy(Device[deviceCount].Name, "RFID Reader");
Device[deviceCount].Type = DEVICE_TYPE_DUAL;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "RFID");
break;
}
case PLUGIN_INIT:
{
Serial.println("RFID plugin init!");
Plugin_008_init = true;
Serial.print(F("INIT : RFID "));
Serial.print(Settings.TaskDevicePin1[event->TaskIndex]);
Serial.print(" & ");
Serial.println(Settings.TaskDevicePin2[event->TaskIndex]);
pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP);
pinMode(Settings.TaskDevicePin2[event->TaskIndex], INPUT_PULLUP);
attachInterrupt(Settings.TaskDevicePin1[event->TaskIndex], Plugin_008_interrupt1, FALLING);
attachInterrupt(Settings.TaskDevicePin2[event->TaskIndex], Plugin_008_interrupt2, FALLING);
success = true;
break;
}
case PLUGIN_ONCE_A_SECOND:
{
if (Plugin_008_init)
{
if ((Plugin_008_bitCount != PLUGIN_008_WGSIZE) && (Plugin_008_bitCount == Plugin_008_bitCountPrev))
{
// must be noise
Plugin_008_bitCount = 0;
Plugin_008_keyBuffer = 0;
}
if (Plugin_008_bitCount == PLUGIN_008_WGSIZE)
{
Plugin_008_bitCount = 0; // Read in the current key and reset everything so that the interrupts can
Plugin_008_keyBuffer = Plugin_008_keyBuffer >> 1; // Strip leading and trailing parity bits from the keyBuffer
Plugin_008_keyBuffer &= 0xFFFFFF;
UserVar[event->BaseVarIndex] = Plugin_008_keyBuffer;
Serial.println(Plugin_008_keyBuffer);
sendData(event->TaskIndex, 1, Settings.TaskDeviceID[event->TaskIndex], event->BaseVarIndex);
// Plugin_008_keyBuffer = 0; // Clear the buffer for the next iteration.
}
Plugin_008_bitCountPrev = Plugin_008_bitCount; // store this value for next check, detect noise
}
break;
}
}
return success;
}
/*********************************************************************/
void Plugin_008_interrupt1()
/*********************************************************************/
{
// We've received a 1 bit. (bit 0 = high, bit 1 = low)
Plugin_008_keyBuffer = Plugin_008_keyBuffer << 1; // Left shift the number (effectively multiplying by 2)
Plugin_008_keyBuffer += 1; // Add the 1 (not necessary for the zeroes)
Plugin_008_bitCount++; // Increment the bit count
}
/*********************************************************************/
void Plugin_008_interrupt2()
/*********************************************************************/
{
// We've received a 0 bit. (bit 0 = low, bit 1 = high)
Plugin_008_keyBuffer = Plugin_008_keyBuffer << 1; // Left shift the number (effectively multiplying by 2)
Plugin_008_bitCount++; // Increment the bit count
}
+63
View File
@@ -0,0 +1,63 @@
//#######################################################################################################
//#################################### Plugin 009: MCP23017 input #######################################
//#######################################################################################################
#define PLUGIN_009
#define PLUGIN_ID_009 9
boolean Plugin_009(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_009;
strcpy(Device[deviceCount].Name, "MCP23017 input");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 16;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0], "Switch");
break;
}
case PLUGIN_COMMAND:
{
byte Par1 = Settings.TaskDevicePort[event->TaskIndex];
Serial.println("MCP23017 Read");
byte portvalue = 0;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte IOBankConfigReg = 0;
byte IOBankValueReg = 0x12;
if (port > 8)
{
port = port - 8;
IOBankConfigReg++;
IOBankValueReg++;
}
// get the current pin status
Wire.beginTransmission(address);
Wire.write(IOBankValueReg); // IO data register
Wire.endTransmission();
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
{
portvalue = ((Wire.read() & _BV(port - 1)) >> (port - 1));
UserVar[event->BaseVarIndex] = (float)portvalue;
Serial.print("MCP : Input Value : ");
Serial.println(UserVar[event->BaseVarIndex]);
success = true;
}
break;
}
}
return success;
}
+56
View File
@@ -0,0 +1,56 @@
//#######################################################################################################
//#################################### Plugin-010: LuxRead ############################################
//#######################################################################################################
#define PLUGIN_010
#define PLUGIN_ID_010 10
#define BH1750_ADDRESS 0x23
boolean Plugin_010_init = false;
boolean Plugin_010(byte function, struct EventStruct *event, String& string)
{
boolean success=false;
switch(function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_010;
strcpy(Device[deviceCount].Name,"LUX BH1750");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0],"Lux");
break;
}
case PLUGIN_COMMAND:
{
if (!Plugin_010_init)
{
Plugin_010_init=true;
Serial.println("Lux init");
Wire.beginTransmission(BH1750_ADDRESS);
Wire.write(0x10); // 1 lx resolution
Wire.endTransmission();
}
Wire.requestFrom(BH1750_ADDRESS, 2);
byte b1 = Wire.read();
byte b2 = Wire.read();
float val=0;
val=((b1<<8)|b2)/1.2;
val=val+15;
UserVar[event->BaseVarIndex] = val;
Serial.print("LUX : Light intensity: ");
Serial.println(UserVar[event->BaseVarIndex]);
success=true;
break;
}
}
return success;
}
+49
View File
@@ -0,0 +1,49 @@
//#######################################################################################################
//#################################### Plugin 011: Pro Mini Digital #####################################
//#######################################################################################################
#define PLUGIN_011
#define PLUGIN_ID_011 11
boolean Plugin_011(byte function, struct EventStruct *event, String& string)
{
boolean success=false;
switch(function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_011;
strcpy(Device[deviceCount].Name,"ProMini Extender Digital");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 1;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].Ports = 14;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0],"Switch");
break;
}
case PLUGIN_COMMAND:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(2); // Digital Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time ?
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print("PMD : Digital: ");
Serial.println(UserVar[event->BaseVarIndex]);
success=true;
break;
}
}
return success;
}
+50
View File
@@ -0,0 +1,50 @@
//#######################################################################################################
//#################################### Plugin 012: Pro Mini Analog ######################################
//#######################################################################################################
#define PLUGIN_012
#define PLUGIN_ID_012 12
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;
strcpy(Device[deviceCount].Name,"ProMini Extender Analog");
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = 1;
Device[deviceCount].Ports = 6;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 1;
strcpy(Device[deviceCount].ValueNames[0],"Analog");
break;
}
case PLUGIN_COMMAND:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(4); // ADC Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time to do the adc stuff
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print("PMADC: Analog: ");
Serial.println(UserVar[event->BaseVarIndex]);
success=true;
break;
}
}
return success;
}
+532
View File
@@ -0,0 +1,532 @@
//********************************************************************************
// Initialize allplugins that where defined earlier
// and initialize the function call pointer into the plugin array
//********************************************************************************
void PluginInit(void)
{
byte x;
// Clear pointer table for all plugins
for (x = 0; x < PLUGIN_MAX; x++)
{
Plugin_ptr[x] = 0;
Plugin_id[x] = 0;
}
x = 0;
#ifdef PLUGIN_001
Plugin_id[x] = 1; Plugin_ptr[x++] = &Plugin_001;
#endif
#ifdef PLUGIN_002
Plugin_id[x] = 2; Plugin_ptr[x++] = &Plugin_002;
#endif
#ifdef PLUGIN_003
Plugin_id[x] = 3; Plugin_ptr[x++] = &Plugin_003;
#endif
#ifdef PLUGIN_004
Plugin_id[x] = 4; Plugin_ptr[x++] = &Plugin_004;
#endif
#ifdef PLUGIN_005
Plugin_id[x] = 5; Plugin_ptr[x++] = &Plugin_005;
#endif
#ifdef PLUGIN_006
Plugin_id[x] = 6; Plugin_ptr[x++] = &Plugin_006;
#endif
#ifdef PLUGIN_007
Plugin_id[x] = 7; Plugin_ptr[x++] = &Plugin_007;
#endif
#ifdef PLUGIN_008
Plugin_id[x] = 8; Plugin_ptr[x++] = &Plugin_008;
#endif
#ifdef PLUGIN_009
Plugin_id[x] = 9; Plugin_ptr[x++] = &Plugin_009;
#endif
#ifdef PLUGIN_010
Plugin_id[x] = 10; Plugin_ptr[x++] = &Plugin_010;
#endif
#ifdef PLUGIN_011
Plugin_id[x] = 11; Plugin_ptr[x++] = &Plugin_011;
#endif
#ifdef PLUGIN_012
Plugin_id[x] = 12; Plugin_ptr[x++] = &Plugin_012;
#endif
#ifdef PLUGIN_013
Plugin_id[x] = 13; Plugin_ptr[x++] = &Plugin_013;
#endif
#ifdef PLUGIN_014
Plugin_id[x] = 14; Plugin_ptr[x++] = &Plugin_014;
#endif
#ifdef PLUGIN_015
Plugin_id[x] = 15; Plugin_ptr[x++] = &Plugin_015;
#endif
#ifdef PLUGIN_016
Plugin_id[x] = 16; Plugin_ptr[x++] = &Plugin_016;
#endif
#ifdef PLUGIN_017
Plugin_id[x] = 17; Plugin_ptr[x++] = &Plugin_017;
#endif
#ifdef PLUGIN_018
Plugin_id[x] = 18; Plugin_ptr[x++] = &Plugin_018;
#endif
#ifdef PLUGIN_019
Plugin_id[x] = 19; Plugin_ptr[x++] = &Plugin_019;
#endif
#ifdef PLUGIN_020
Plugin_id[x] = 20; Plugin_ptr[x++] = &Plugin_020;
#endif
#ifdef PLUGIN_021
Plugin_id[x] = 21; Plugin_ptr[x++] = &Plugin_021;
#endif
#ifdef PLUGIN_022
Plugin_id[x] = 22; Plugin_ptr[x++] = &Plugin_022;
#endif
#ifdef PLUGIN_023
Plugin_id[x] = 23; Plugin_ptr[x++] = &Plugin_023;
#endif
#ifdef PLUGIN_024
Plugin_id[x] = 24; Plugin_ptr[x++] = &Plugin_024;
#endif
#ifdef PLUGIN_025
Plugin_id[x] = 25; Plugin_ptr[x++] = &Plugin_025;
#endif
#ifdef PLUGIN_026
Plugin_id[x] = 26; Plugin_ptr[x++] = &Plugin_026;
#endif
#ifdef PLUGIN_027
Plugin_id[x] = 27; Plugin_ptr[x++] = &Plugin_027;
#endif
#ifdef PLUGIN_028
Plugin_id[x] = 28; Plugin_ptr[x++] = &Plugin_028;
#endif
#ifdef PLUGIN_029
Plugin_id[x] = 29; Plugin_ptr[x++] = &Plugin_029;
#endif
#ifdef PLUGIN_030
Plugin_id[x] = 30; Plugin_ptr[x++] = &Plugin_030;
#endif
#ifdef PLUGIN_031
Plugin_id[x] = 31; Plugin_ptr[x++] = &Plugin_031;
#endif
#ifdef PLUGIN_032
Plugin_id[x] = 32; Plugin_ptr[x++] = &Plugin_032;
#endif
#ifdef PLUGIN_033
Plugin_id[x] = 33; Plugin_ptr[x++] = &Plugin_033;
#endif
#ifdef PLUGIN_034
Plugin_id[x] = 34; Plugin_ptr[x++] = &Plugin_034;
#endif
#ifdef PLUGIN_035
Plugin_id[x] = 35; Plugin_ptr[x++] = &Plugin_035;
#endif
#ifdef PLUGIN_036
Plugin_id[x] = 36; Plugin_ptr[x++] = &Plugin_036;
#endif
#ifdef PLUGIN_037
Plugin_id[x] = 37; Plugin_ptr[x++] = &Plugin_037;
#endif
#ifdef PLUGIN_038
Plugin_id[x] = 38; Plugin_ptr[x++] = &Plugin_038;
#endif
#ifdef PLUGIN_039
Plugin_id[x] = 39; Plugin_ptr[x++] = &Plugin_039;
#endif
#ifdef PLUGIN_040
Plugin_id[x] = 40; Plugin_ptr[x++] = &Plugin_040;
#endif
#ifdef PLUGIN_041
Plugin_id[x] = 41; Plugin_ptr[x++] = &Plugin_041;
#endif
#ifdef PLUGIN_042
Plugin_id[x] = 42; Plugin_ptr[x++] = &Plugin_042;
#endif
#ifdef PLUGIN_043
Plugin_id[x] = 43; Plugin_ptr[x++] = &Plugin_043;
#endif
#ifdef PLUGIN_044
Plugin_id[x] = 44; Plugin_ptr[x++] = &Plugin_044;
#endif
#ifdef PLUGIN_045
Plugin_id[x] = 45; Plugin_ptr[x++] = &Plugin_045;
#endif
#ifdef PLUGIN_046
Plugin_id[x] = 46; Plugin_ptr[x++] = &Plugin_046;
#endif
#ifdef PLUGIN_047
Plugin_id[x] = 47; Plugin_ptr[x++] = &Plugin_047;
#endif
#ifdef PLUGIN_048
Plugin_id[x] = 48; Plugin_ptr[x++] = &Plugin_048;
#endif
#ifdef PLUGIN_049
Plugin_id[x] = 49; Plugin_ptr[x++] = &Plugin_049;
#endif
#ifdef PLUGIN_050
Plugin_id[x] = 50; Plugin_ptr[x++] = &Plugin_050;
#endif
#ifdef PLUGIN_051
Plugin_id[x] = 51; Plugin_ptr[x++] = &Plugin_051;
#endif
#ifdef PLUGIN_052
Plugin_id[x] = 52; Plugin_ptr[x++] = &Plugin_052;
#endif
#ifdef PLUGIN_053
Plugin_id[x] = 53; Plugin_ptr[x++] = &Plugin_053;
#endif
#ifdef PLUGIN_054
Plugin_id[x] = 54; Plugin_ptr[x++] = &Plugin_054;
#endif
#ifdef PLUGIN_055
Plugin_id[x] = 55; Plugin_ptr[x++] = &Plugin_055;
#endif
#ifdef PLUGIN_056
Plugin_id[x] = 56; Plugin_ptr[x++] = &Plugin_056;
#endif
#ifdef PLUGIN_057
Plugin_id[x] = 57; Plugin_ptr[x++] = &Plugin_057;
#endif
#ifdef PLUGIN_058
Plugin_id[x] = 58; Plugin_ptr[x++] = &Plugin_058;
#endif
#ifdef PLUGIN_059
Plugin_id[x] = 59; Plugin_ptr[x++] = &Plugin_059;
#endif
#ifdef PLUGIN_060
Plugin_id[x] = 60; Plugin_ptr[x++] = &Plugin_060;
#endif
#ifdef PLUGIN_061
Plugin_id[x] = 61; Plugin_ptr[x++] = &Plugin_061;
#endif
#ifdef PLUGIN_062
Plugin_id[x] = 62; Plugin_ptr[x++] = &Plugin_062;
#endif
#ifdef PLUGIN_063
Plugin_id[x] = 63; Plugin_ptr[x++] = &Plugin_063;
#endif
#ifdef PLUGIN_064
Plugin_id[x] = 64; Plugin_ptr[x++] = &Plugin_064;
#endif
#ifdef PLUGIN_065
Plugin_id[x] = 65; Plugin_ptr[x++] = &Plugin_065;
#endif
#ifdef PLUGIN_066
Plugin_id[x] = 66; Plugin_ptr[x++] = &Plugin_066;
#endif
#ifdef PLUGIN_067
Plugin_id[x] = 67; Plugin_ptr[x++] = &Plugin_067;
#endif
#ifdef PLUGIN_068
Plugin_id[x] = 68; Plugin_ptr[x++] = &Plugin_068;
#endif
#ifdef PLUGIN_069
Plugin_id[x] = 69; Plugin_ptr[x++] = &Plugin_069;
#endif
#ifdef PLUGIN_070
Plugin_id[x] = 70; Plugin_ptr[x++] = &Plugin_070;
#endif
#ifdef PLUGIN_071
Plugin_id[x] = 71; Plugin_ptr[x++] = &Plugin_071;
#endif
#ifdef PLUGIN_072
Plugin_id[x] = 72; Plugin_ptr[x++] = &Plugin_072;
#endif
#ifdef PLUGIN_073
Plugin_id[x] = 73; Plugin_ptr[x++] = &Plugin_073;
#endif
#ifdef PLUGIN_074
Plugin_id[x] = 74; Plugin_ptr[x++] = &Plugin_074;
#endif
#ifdef PLUGIN_075
Plugin_id[x] = 75; Plugin_ptr[x++] = &Plugin_075;
#endif
#ifdef PLUGIN_076
Plugin_id[x] = 76; Plugin_ptr[x++] = &Plugin_076;
#endif
#ifdef PLUGIN_077
Plugin_id[x] = 77; Plugin_ptr[x++] = &Plugin_077;
#endif
#ifdef PLUGIN_078
Plugin_id[x] = 78; Plugin_ptr[x++] = &Plugin_078;
#endif
#ifdef PLUGIN_079
Plugin_id[x] = 79; Plugin_ptr[x++] = &Plugin_079;
#endif
#ifdef PLUGIN_080
Plugin_id[x] = 80; Plugin_ptr[x++] = &Plugin_080;
#endif
#ifdef PLUGIN_081
Plugin_id[x] = 81; Plugin_ptr[x++] = &Plugin_081;
#endif
#ifdef PLUGIN_082
Plugin_id[x] = 82; Plugin_ptr[x++] = &Plugin_082;
#endif
#ifdef PLUGIN_083
Plugin_id[x] = 83; Plugin_ptr[x++] = &Plugin_083;
#endif
#ifdef PLUGIN_084
Plugin_id[x] = 84; Plugin_ptr[x++] = &Plugin_084;
#endif
#ifdef PLUGIN_085
Plugin_id[x] = 85; Plugin_ptr[x++] = &Plugin_085;
#endif
#ifdef PLUGIN_086
Plugin_id[x] = 86; Plugin_ptr[x++] = &Plugin_086;
#endif
#ifdef PLUGIN_087
Plugin_id[x] = 87; Plugin_ptr[x++] = &Plugin_087;
#endif
#ifdef PLUGIN_088
Plugin_id[x] = 88; Plugin_ptr[x++] = &Plugin_088;
#endif
#ifdef PLUGIN_089
Plugin_id[x] = 89; Plugin_ptr[x++] = &Plugin_089;
#endif
#ifdef PLUGIN_090
Plugin_id[x] = 90; Plugin_ptr[x++] = &Plugin_090;
#endif
#ifdef PLUGIN_091
Plugin_id[x] = 91; Plugin_ptr[x++] = &Plugin_091;
#endif
#ifdef PLUGIN_092
Plugin_id[x] = 92; Plugin_ptr[x++] = &Plugin_092;
#endif
#ifdef PLUGIN_093
Plugin_id[x] = 93; Plugin_ptr[x++] = &Plugin_093;
#endif
#ifdef PLUGIN_094
Plugin_id[x] = 94; Plugin_ptr[x++] = &Plugin_094;
#endif
#ifdef PLUGIN_095
Plugin_id[x] = 95; Plugin_ptr[x++] = &Plugin_095;
#endif
#ifdef PLUGIN_096
Plugin_id[x] = 96; Plugin_ptr[x++] = &Plugin_096;
#endif
#ifdef PLUGIN_097
Plugin_id[x] = 97; Plugin_ptr[x++] = &Plugin_097;
#endif
#ifdef PLUGIN_098
Plugin_id[x] = 98; Plugin_ptr[x++] = &Plugin_098;
#endif
#ifdef PLUGIN_099
Plugin_id[x] = 99; Plugin_ptr[x++] = &Plugin_099;
#endif
#ifdef PLUGIN_100
Plugin_id[x] = 100; Plugin_ptr[x++] = &Plugin_100;
#endif
#ifdef PLUGIN_250
Plugin_id[x] = 250; Plugin_ptr[x++] = &Plugin_250;
#endif
#ifdef PLUGIN_251
Plugin_id[x] = 251; Plugin_ptr[x++] = &Plugin_251;
#endif
#ifdef PLUGIN_252
Plugin_id[x] = 252; Plugin_ptr[x++] = &Plugin_252;
#endif
#ifdef PLUGIN_253
Plugin_id[x] = 253; Plugin_ptr[x++] = &Plugin_253;
#endif
#ifdef PLUGIN_254
Plugin_id[x] = 254; Plugin_ptr[x++] = &Plugin_254;
#endif
#ifdef PLUGIN_255
Plugin_id[x] = 255; Plugin_ptr[x++] = &Plugin_255;
#endif
PluginCall(PLUGIN_DEVICE_ADD, 0, dummyString);
PluginCall(PLUGIN_INIT_ALL, 0, dummyString);
}
/*********************************************************************************************\
* Function call to all or specific plugins
\*********************************************************************************************/
byte PluginCall(byte Function, struct EventStruct *Event, String& str)
{
int x;
switch (Function)
{
// Call to all plugins
//case PLUGIN_EVENT_IN:
//case PLUGIN_EVENT_OUT:
case PLUGIN_DEVICE_ADD:
for (x = 0; x < PLUGIN_MAX; x++)
if (Plugin_id[x] != 0)
Plugin_ptr[x](Function, Event, str);
return true;
break;
// Call to all plugins. Return at first match
case PLUGIN_EVENTLIST_ADD:
for (x = 0; x < PLUGIN_MAX; x++)
if (Plugin_id[x] != 0)
if (Plugin_ptr[x](Function, Event, str))
return true;
break;
// Call to all plugins that are used in a task
case PLUGIN_ONCE_A_SECOND:
case PLUGIN_TEN_PER_SECOND:
case PLUGIN_INIT_ALL:
{
struct EventStruct TempEvent;
if (Function == PLUGIN_INIT_ALL)
Function = PLUGIN_INIT;
for (byte y = 0; y < TASKS_MAX; y++)
{
if (Settings.TaskDeviceNumber[y] != 0)
{
TempEvent.TaskIndex = y;
TempEvent.BaseVarIndex = y * VARS_PER_TASK;
for (x = 0; x < PLUGIN_MAX; x++)
{
if (Plugin_id[x] == Settings.TaskDeviceNumber[y])
{
if ((Function != PLUGIN_ONCE_A_SECOND) && (Function != PLUGIN_TEN_PER_SECOND))
{
//Serial.print("All Used Plugin nr ");
//Serial.print(Plugin_id[x]);
//Serial.print(" tasknr ");
//Serial.println(y);
}
Plugin_ptr[x](Function, &TempEvent, str);
}
}
}
}
return true;
break;
}
// Call to specific plugin that is used for this task
case PLUGIN_INIT:
case PLUGIN_WEBFORM_LOAD:
case PLUGIN_WEBFORM_SAVE:
case PLUGIN_WEBFORM_VALUES:
case PLUGIN_COMMAND:
for (x = 0; x < PLUGIN_MAX; x++)
{
if ((Plugin_id[x] != 0 ) && (Plugin_id[x] == Settings.TaskDeviceNumber[Event->TaskIndex]))
{
Event->BaseVarIndex = Event->TaskIndex * VARS_PER_TASK;
//Serial.print("This Plugin nr ");
//Serial.print(Plugin_id[x]);
//Serial.print(" tasknr ");
//Serial.println(Event->TaskIndex);
return Plugin_ptr[x](Function, Event, str);
}
}
return false;
break;
}// case
return false;
}
+134
View File
@@ -0,0 +1,134 @@
// R017 08-09-2015
// Fixed factory reset formula settings.
// Preliminary support for PiDome MQTT protocol
// Total rework of all sensor devices, moved code to plugin files for easier maintenance and extensibility
// Plugins can extend the device webform with custom settings
// Changed EEPROM size to 2048
// System no longers needs a reboot after adding/changing specific (IRQ) devices like pulsecounters
// Changed Device table, shows valuenames for devices
// Prevent input switches from firing at boot time, first read current state during init
// Added option to inverse input switch logic
// Changed WPA key limit to 63
// Some code cleanup, removing old debug commands
// R016 29-08-2015
// Preliminary support for IO extender based on Arduino Pro Mini through I2C
// Added GPIO-9 and GPIO-10 for boards equipped with an ESP12E module (NodeMCU V1.0)
// Finished support for PCF8591 4 channel Analog to Digital converter.
// Added support for MCP23017 input ports
// Unit Name is shown in html title
// Show 'well known' devices in the I2C scanner based on their I2C address
// Added option to use simple formulas on device values like "%value%/1000"
// Fixed char string handling that should be 25 chars max
// Added option to turn on/off internal pullup for switch input pins
// Added option to set a name for each task (also used for OpenHAB MQTT publishing)
// Preliminary support for OpenHAB MQTT protocol
// R015 22-08-2015
// Fixed a bug in DHT22 device
// Fixed a bug in setting for default delay
// Changed debug info
// Changed device tab, added more pin info and cancel button
// Fixed syslog loop bug
// R014 20-08-2015
// Redesigned device configuration mechanisme
// Changed password timeout to 5 minutes
// Added direct GPIO output control without password request
// R013 15-08-2015
// Added configurable message delay in ms (delay between messages to controller)
// Changed login password field to type 'password'
// Fixed io pin settings for Dallas/DHT for inconsecutive pin configuration (ESP-01)
// Support for ThingsSpeak "controller" (webservice)
// R012 07-08-2015
// IMPORTANT NOTICE: this release needs ESP Package version 1.6.5-947-g39819f0, built on Jul 23, 2015)
// If udp port = 0 no actions!
// Used sprintf_P to save more RAM
// Added login page and admin password
// Added hardware custom gpio pin selection
// Added sanity check on BMP085 pressure values
// R011 12-07-2015
// Changed javascript link buttons into CSS button styled href links
// Fixed Main button, only worked on IE.
// Changed connectionFailures counting
// Reboot from main loop instead of web event callback
// Changed logging configuration
// BaudRate can be configured through webgui, defaults to 115200
// Added Serial.setDebugOutput(true) if serial loglevel = 4 (debug_more level)
// Added telnet protocol to send variable data to a Nodo Mega controller
// Added webgui I2C scanner
// Added webgui Wifi scanner
// Fixed bug in settingssave on devices
// Added delay(1) in Domoticz_sendData, while available loop
// R010 30-06-2015
// Changed freemem request in root web page
// Some memory reduced by eliminating globals
// Init MQTT at boot only if protocol is set to MQTT
// Added syslog level for detailed logging
// Added menu buttons in webgui and stuctured data as HTML tables
// R009 26-06-2015
// Changed switch pin from GPIO-0 to wired input pin 1
// Added config options for static IP/gateway/subnet
// Using LCD library instead of local functions
// Added MQTT library
// Added JSON parse library
// Needs Domoticz 2560 and Mosquitto 3.1.1 or higher
// Reduced EEPROM from 4096->1024 (needs a RAM buffer from same size!)
// Added basic logging to web interface
// R008 06-06-2015
// UDP listening port web configurable
// If UDP port enabled, also send IDX events to this UDP port
// Added Domotics lightswitch option, input on GPIO-0 pin.
// R007 01-06-2015
// use custom counter for WD instead of millis() (millis does not reset on ESP.Reset)
// Changed BAUDrate to 9600
// DomoticzGet <type>, <idx> test command (via serial)
// R006 23-05-2015
// Stored many constant strings to progmem
// delay(1) into http 'while' client check
// delay(10) in main loop instead of yield()
// DomoticzSend <type>,<idx>,<value> test command (via serial)
// Disabled analogRead, seems broken in g8cd3697 (use millis()/1000 as demo value!)
// R005 21-05-2015
// Some fixes to be compabtible with Arduino 1.6.4 using ESP board addon 1.6.4.-628-g545ffde
// R004 18-05-2015
// Fixed setting ip_octet to 0 on reset
// Fixed missing ; in domoticz send case 3:
// Fixed: Serial Pulse settings command did not work.
// Very experimental stuff for Nodo events on I2C (Nodo 3.8, R818)
// Some code optimization in string/char-array handling within webserver functions
// Replaced 'reboot function call' with ESP.reset
// Added hardware config web page to change io pins on ESP-01 boards
// Added basic stuff for UDP communications and syslog function
// Listens on UDP port 65500 for commands.
// Added connectionFailure counter
// Sends "WD <uptime in seconds> CF <connection failures>" every 30 seconds on serial to reset external watchdog
// Sends "WD <uptime in seconds> CF <connection failures>" to syslog if configured
// Delayed reboot on empty IP adress (in case of DHCP issue)
// Delayed reboot after 30 connection failures
// R003 06-05-2015
// Start AP mode if no connection, leave AP mode 30 seconds after succesfull connection
// Added option to set a fixed last octet of the ESP IP address (remaining config is still done with DHCP)
// This is the easiest way. You can still change subnet,gw,dns with DHCP but have a fixed IP
// This is convenient to control ESP with Domoticz http requests (relais, io expander, etc)
// Support for Domoticz multiple value sensor types (temp/hum/baro)
// Added support for pulsecounter
// R002 02-05-2015
// Added configuration webinterface
// Start AP mode is ssid is not configured
// R001 01-05-2015
// First 'stable' edition (meaning that it does not crash during boot of within one minute...)