Browse Source

Using constants in api configuration calls

fastled
Xose Pérez 7 years ago
parent
commit
816a6f56e8
9 changed files with 28 additions and 26 deletions
  1. +1
    -1
      code/espurna/analog.ino
  2. +14
    -14
      code/espurna/config/sensors.h
  3. +2
    -2
      code/espurna/dht.ino
  4. +1
    -1
      code/espurna/ds18b20.ino
  5. +1
    -1
      code/espurna/emon.ino
  6. +1
    -1
      code/espurna/light.ino
  7. +3
    -3
      code/espurna/pow.ino
  8. +2
    -2
      code/espurna/relay.ino
  9. +3
    -1
      code/espurna/web.ino

+ 1
- 1
code/espurna/analog.ino View File

@ -22,7 +22,7 @@ void analogSetup() {
pinMode(ANALOG_PIN, INPUT); pinMode(ANALOG_PIN, INPUT);
apiRegister("/api/analog", "analog", [](char * buffer, size_t len) {
apiRegister(ANALOG_TOPIC, ANALOG_TOPIC, [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", getAnalog()); snprintf(buffer, len, "%d", getAnalog());
}); });


+ 14
- 14
code/espurna/config/sensors.h View File

@ -17,8 +17,8 @@
#define DHT_UPDATE_INTERVAL 60000 #define DHT_UPDATE_INTERVAL 60000
#define DHT_TYPE DHT22 #define DHT_TYPE DHT22
#define DHT_TIMING 11 #define DHT_TIMING 11
#define DHT_TEMPERATURE_TOPIC "/temperature"
#define DHT_HUMIDITY_TOPIC "/humidity"
#define DHT_TEMPERATURE_TOPIC "temperature"
#define DHT_HUMIDITY_TOPIC "humidity"
#define HUMIDITY_NORMAL 0 #define HUMIDITY_NORMAL 0
#define HUMIDITY_COMFORTABLE 1 #define HUMIDITY_COMFORTABLE 1
@ -32,7 +32,7 @@
#define ANALOG_PIN 0 #define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000 #define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "/analog"
#define ANALOG_TOPIC "analog"
#if ENABLE_ANALOG #if ENABLE_ANALOG
#undef ENABLE_ADC_VCC #undef ENABLE_ADC_VCC
@ -46,7 +46,7 @@
#define DS_PIN 14 #define DS_PIN 14
#define DS_UPDATE_INTERVAL 60000 #define DS_UPDATE_INTERVAL 60000
#define DS_TEMPERATURE_TOPIC "/temperature"
#define DS_TEMPERATURE_TOPIC "temperature"
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Custom current sensor // Custom current sensor
@ -86,9 +86,9 @@
#define EMON_INTERVAL 10000 #define EMON_INTERVAL 10000
#define EMON_MEASUREMENTS 6 #define EMON_MEASUREMENTS 6
#define EMON_MAINS_VOLTAGE 230 #define EMON_MAINS_VOLTAGE 230
#define EMON_APOWER_TOPIC "/apower"
#define EMON_ENERGY_TOPIC "/energy"
#define EMON_CURRENT_TOPIC "/current"
#define EMON_APOWER_TOPIC "apower"
#define EMON_ENERGY_TOPIC "energy"
#define EMON_CURRENT_TOPIC "current"
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// HLW8012 power sensor (Sonoff POW) // HLW8012 power sensor (Sonoff POW)
@ -104,13 +104,13 @@
#define POW_CURRENT_R 0.001 #define POW_CURRENT_R 0.001
#define POW_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k #define POW_VOLTAGE_R_UP ( 5 * 470000 ) // Real: 2280k
#define POW_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k #define POW_VOLTAGE_R_DOWN ( 1000 ) // Real 1.009k
#define POW_POWER_TOPIC "/power"
#define POW_CURRENT_TOPIC "/current"
#define POW_VOLTAGE_TOPIC "/voltage"
#define POW_APOWER_TOPIC "/apower"
#define POW_RPOWER_TOPIC "/rpower"
#define POW_PFACTOR_TOPIC "/pfactor"
#define POW_ENERGY_TOPIC "/energy"
#define POW_POWER_TOPIC "power"
#define POW_CURRENT_TOPIC "current"
#define POW_VOLTAGE_TOPIC "voltage"
#define POW_APOWER_TOPIC "apower"
#define POW_RPOWER_TOPIC "rpower"
#define POW_PFACTOR_TOPIC "pfactor"
#define POW_ENERGY_TOPIC "energy"
#define POW_UPDATE_INTERVAL 5000 #define POW_UPDATE_INTERVAL 5000
#define POW_REPORT_EVERY 12 #define POW_REPORT_EVERY 12


+ 2
- 2
code/espurna/dht.ino View File

@ -30,10 +30,10 @@ unsigned int getDHTHumidity() {
void dhtSetup() { void dhtSetup() {
dht.begin(); dht.begin();
apiRegister("/api/temperature", "temperature", [](char * buffer, size_t len) {
apiRegister(DHT_TEMPERATURE_TOPIC, DHT_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dhtTemperature, len-1, 1, buffer); dtostrf(_dhtTemperature, len-1, 1, buffer);
}); });
apiRegister("/api/humidity", "humidity", [](char * buffer, size_t len) {
apiRegister(DHT_HUMIDITY_TOPIC, DHT_HUMIDITY_TOPIC, [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", _dhtHumidity); snprintf(buffer, len, "%d", _dhtHumidity);
}); });
} }


+ 1
- 1
code/espurna/ds18b20.ino View File

@ -37,7 +37,7 @@ void dsSetup() {
ds18b20.begin(); ds18b20.begin();
ds18b20.setWaitForConversion(false); ds18b20.setWaitForConversion(false);
apiRegister("/api/temperature", "temperature", [](char * buffer, size_t len) {
apiRegister(DS_TEMPERATURE_TOPIC, DS_TEMPERATURE_TOPIC, [](char * buffer, size_t len) {
dtostrf(_dsTemperature, len-1, 1, buffer); dtostrf(_dsTemperature, len-1, 1, buffer);
}); });
} }


+ 1
- 1
code/espurna/emon.ino View File

@ -97,7 +97,7 @@ void powerMonitorSetup() {
brzo_i2c_end_transaction(); brzo_i2c_end_transaction();
#endif #endif
apiRegister("/api/power", "power", [](char * buffer, size_t len) {
apiRegister(EMON_APOWER_TOPIC, EMON_APOWER_TOPIC, [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", _power); snprintf(buffer, len, "%d", _power);
}); });


+ 1
- 1
code/espurna/light.ino View File

@ -165,7 +165,7 @@ void lightMQTTCallback(unsigned int type, const char * topic, const char * paylo
void lightSetupAPI() { void lightSetupAPI() {
// API entry points (protected with apikey) // API entry points (protected with apikey)
apiRegister("/api/color", "color",
apiRegister(MQTT_TOPIC_COLOR, MQTT_TOPIC_COLOR,
[](char * buffer, size_t len) { [](char * buffer, size_t len) {
snprintf(buffer, len, "%s", lightColor().c_str()); snprintf(buffer, len, "%s", lightColor().c_str());
}, },


+ 3
- 3
code/espurna/pow.ino View File

@ -145,13 +145,13 @@ void powSetup() {
powRetrieveCalibration(); powRetrieveCalibration();
// API definitions // API definitions
apiRegister("/api/power", "power", [](char * buffer, size_t len) {
apiRegister(POW_POWER_TOPIC, POW_POWER_TOPIC, [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", getActivePower()); snprintf(buffer, len, "%d", getActivePower());
}); });
apiRegister("/api/current", "current", [](char * buffer, size_t len) {
apiRegister(POW_CURRENT_TOPIC, POW_CURRENT_TOPIC, [](char * buffer, size_t len) {
dtostrf(getCurrent(), len-1, 2, buffer); dtostrf(getCurrent(), len-1, 2, buffer);
}); });
apiRegister("/api/voltage", "voltage", [](char * buffer, size_t len) {
apiRegister(POW_VOLTAGE_TOPIC, POW_VOLTAGE_TOPIC, [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", getVoltage()); snprintf(buffer, len, "%d", getVoltage());
}); });


+ 2
- 2
code/espurna/relay.ino View File

@ -266,10 +266,10 @@ void relaySetupAPI() {
for (unsigned int relayID=0; relayID<relayCount(); relayID++) { for (unsigned int relayID=0; relayID<relayCount(); relayID++) {
char url[15]; char url[15];
sprintf(url, "/api/relay/%d", relayID);
sprintf(url, "%s/%d", MQTT_TOPIC_RELAY, relayID);
char key[10]; char key[10];
sprintf(key, "relay%d", relayID);
sprintf(key, "%s%d", MQTT_TOPIC_RELAY, relayID);
apiRegister(url, key, apiRegister(url, key,
[relayID](char * buffer, size_t len) { [relayID](char * buffer, size_t len) {


+ 3
- 1
code/espurna/web.ino View File

@ -684,7 +684,9 @@ void apiRegister(const char * url, const char * key, apiGetCallbackFunction getF
// Store it // Store it
web_api_t api; web_api_t api;
api.url = strdup(url);
char buffer[40];
snprintf(buffer, 39, "/api/%s", url);
api.url = strdup(buffer);
api.key = strdup(key); api.key = strdup(key);
api.getFn = getFn; api.getFn = getFn;
api.putFn = putFn; api.putFn = putFn;


Loading…
Cancel
Save