Advertisement
Guest User

CONFIG_BLOCK Problem

a guest
Aug 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.77 KB | None | 0 0
  1. #include <max6675.h>
  2.  
  3. #include <ESPArto.h>
  4.  
  5. ESPARTO_CONFIG_BLOCK cb={
  6.     {CONFIG(ESPARTO_SSID),"MELINET"},
  7.     {CONFIG(ESPARTO_PASSWORD),"THISISMYNETWORK"},
  8.     {CONFIG(ESPARTO_DEVICE_NAME),"Burn"},
  9.     {CONFIG(ESPARTO_WEB_USER),"admin"},
  10.     {CONFIG(ESPARTO_WEB_PASS),"admin"},
  11.     {CONFIG(ESPARTO_MQTT_SRV),"192.168.0.12"}, // can also be domain name
  12.     {CONFIG(ESPARTO_MQTT_PORT),"1883"}, // note it is still a string
  13.     {CONFIG(ESPARTO_MQTT_USER),""}, // can omit
  14.     {CONFIG(ESPARTO_MQTT_PASS),""}, // can omit
  15.     {CONFIG(ESPARTO_WILL_TOPIC),"lwt"}, // can omit
  16.     {CONFIG(ESPARTO_WILL_MSG),"Esparto has crashed!"} // can omit
  17. };
  18. ESPArto  Esparto(cb);
  19.  
  20. // Global variables
  21.  
  22. // Pin definitions
  23. int const thermoDO = D5;
  24. int const thermoCLK = D3;
  25. int const thermoCS_0 = D0;
  26. int const oneWireBus = D7;
  27. int const pumpRelay = D8;
  28. int const fanRelay = D6;
  29. int const fanSwitch = D4;
  30.  
  31. // Constants
  32. #define debounce 20 // debounce value in ms
  33. #define frequency 100
  34.  
  35. // functions for handling fan switch press
  36.  
  37. void shortPress(int hilo, int unused){
  38.   // Turn fan on
  39.   Esparto.logicalWrite(fanRelay,ON);
  40. }
  41.  
  42. void longPress(int hilo, int unused){
  43.   // Turn fan off
  44.   Esparto.logicalWrite(fanRelay,OFF);
  45. }
  46.  
  47. void progress(int stage, int unused){}
  48.  
  49. // Functions for handling flue temperature
  50.  
  51. MAX6675 t0(thermoCLK, thermoCS_0, thermoDO);
  52. int const pumpOnTemp = 60;
  53.  
  54. void flueCheck(){
  55.   Esparto.publish("hello/world", "boo");
  56.   Serial.println("Doing flue temp check");
  57.   int flueTemp = t0.readCelsius();
  58.   if (flueTemp >= pumpOnTemp){
  59.     Esparto.logicalWrite(pumpRelay, ON);
  60.   }else if(flueTemp < (pumpOnTemp * 0.6)){
  61.     Esparto.logicalWrite(pumpRelay, OFF);
  62.     Esparto.logicalWrite(fanRelay, OFF);
  63.   }
  64. }
  65.  
  66. void onMqttConnect(void){
  67.   Serial.println("MQTT connected");
  68. }
  69.  
  70. void setupHardware() {
  71.   Serial.begin(115200);
  72.   //ESPARTO_HEADER(Serial); // not necessary, just helps does the Serial begin for you
  73.   // define BUILTIN_LED as output. Most ESP8266 have LED as "active LOW" i.e. it is ON when pin is 0
  74.   // and is OFF when pin is 1
  75.   // Turn of BUILTIN_LED as it needs to be an input for the switch!
  76.   //Esparto.Output(BUILTIN_LED);
  77.   // Fan switch
  78.   Esparto.Output(fanRelay, HIGH, OFF);
  79.   Esparto.MultiStage(fanSwitch,INPUT,debounce,frequency, // notify every 100ms
  80.       progress,
  81.       {
  82.         {1000,shortPress}, // anything up to 1sec is "short"
  83.         {5000,longPress} // 1s - 5s is "long"
  84.       }
  85.     );
  86.   // Flue thermocouple
  87.   Esparto.Output(pumpRelay, HIGH, OFF);
  88.   Esparto.every(10000,flueCheck);
  89.   //Esparto.flashLED(1000);
  90.   Serial.println("Hello world");
  91.   ESPARTO_CONFIG_BLOCK::iterator it = cb.begin();
  92.   while(it != cb.end()){
  93.     Serial.println(it->first.c_str());
  94.     Serial.println(it->second.c_str());
  95.     it++;
  96.   }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement