How Connect Arduino Industrial 101 to Cayenne

How Connect Arduino Industrial 101 to Cayenne over MQTT, and send data from BMP180 and TSL2561.

3 Likes

Cool project @tad.dvor :slight_smile:
~B

2 Likes

Nice!!

1 Like

This project got lots of love from SparkFun and Arduino (and of course Cayenne) through twitter!

~B

2 Likes

With the “CIAO” library, how can I read variables from Cayenne?

can you provide a link to this library?

yes, to write I use:

Ciao.write(F("mqtt"),F("v1/ec0ca..../things/97e63...../data/30"), message);

to read does not work.

are there any examples on how to read?
Here are the command for cayenne Cayenne Docs

The retain flag is not set so you’re not going to be able to read a value unless you subscribe to the topic. As Shramik said, can you link the library you are using?

Voi siete molto gentili.
Thank you all for your help.
I have anacora the problem.
Link library:

i am not familiar with caio library and that a looked at it. any specific reason for using ciao library?

I used the CAYENNE libraries, they work well but they are too big.
The CIAO library is much lighter.

What is your use case? and are you using the arduino industrial 101?

I use arduino industrial 101.
The sketch, without the CAYENNE library, uses 55% of the memory.
The sketch, with the CAYENNE library, uses 104% of the memory.

Ok, I see how it should work now. Can you share your sketch? Pretty sure I have an industrial 101 somewhere at home that I can test it with. You should be able to config ciao as per this page https://www.arduino.cc/en/Reference/CiaoMQTT then use Ciao.read(“mqtt”); in a loop to read messages received.

Good morning adam,

I attach my final schedule.

#include "Adafruit_MCP23017.h"
#include <avr/wdt.h>
#include <Ciao.h>
#include <ArduinoJson.h>

Adafruit_MCP23017 mcp1; //Istanza scheda di espansine

//----INPUT----
bool I[9];
bool Iold[9];
// I1 : Cronotermostato WIFI

//----TEMPERATURE----
float T[4];
bool eT[4]; // Errore sulla sonda
// T0 : Temperatura termocucina a legna 
// T1 : Temperatura panelli solari
// T2 : Temperatura bollitore parte bassa
// T3 : Temperatura bollitore parte alta 

//----OUTPUT----
bool O[9];
bool Oold[9]; 
// O1 : Pompa stufa a legna
// O2 : Pompa scalda salviette
// O3 : Pompa riscaldamento pavimento
// O4 : Comando caldaia a Gas
// O5 : Pompa pannelli solari

//----Mercker---
bool M[3];
// M0 : Antigelo casa
// M1 : Antigelo solare
// M2 : Antigelo stufa legna

//----Parametri-----
float TI = 2.0;         //Temperatura d'isteresi °C
float DT02 = 10.0;      //Temperatura differenziale tra sonta T0 stufa e T2 bollitore inferiore
float TAG = 4.0;        //Temperatura antigelo °C
float TAH = 40.0;       //Temperatura di integrazione °C
float TMinLegna = 50.0;       //Temperatura di integrazione °C
bool cmdRSV = 1; //Abilita scalda salviette
bool cmdRPV = 1; //Abilita riscaldamento a pavimento


unsigned long lastMillis = 0;
unsigned long lastMillis2 = 0;
float mes;

void setup() {

  
//*****INIZIALIZZAZIONE SCHEDA ESPANSIONE*****
    mcp1.begin(0);            //Inizializza l'espansione. 0 e' l'indirizzo consigurato con i selettori  sulla scheda
    int pin= 0;
    while (pin<16){
      if (pin<8){
         mcp1.pinMode(pin, OUTPUT);  //Inizializza esempio: il GPA0 come l'ingresso, che corisponde a 1
      } else {
         mcp1.pinMode(pin, INPUT);   //Inizializza esempio: il GPB0 come l'ingresso, che corisponde a 8 
         //mcp1.pullUp(pin, HIGH);   //Attiva la resistenza di pull up interna al CIP
      }
      pin = pin + 1;
    }
//*****INIZIALIZZAZIONE SCHEDA ESPANSIONE*****
    

     Ciao.begin(); // Per comunicare con linino e internet

  //abilito il watchdog e imposto come tempo di reser 2 secondi
  wdt_enable(WDTO_8S);
}

void loop() {

  leggiParametri();
  leggiINPUT();
  leggiTEMP();

  stufaLEGNA();
  caldaiaGAS();
  riscaldamento();
  pompaSolare();
  if (millis()  > 10000)  {
    scriviUSCITE();
  }

  
  scriviWEB();
  
  //resetto il watchdog
  wdt_reset();
}

void leggiParametri(){
    if ((millis() - lastMillis2) > (10000))  {
      CiaoData data = Ciao.read(F("file"),F("ParCT.txt"));
    
      if (!data.isEmpty() && !data.isError()) {
          String message = data.get(2);
          message.toLowerCase();
          DynamicJsonDocument doc(124); //controllare dimesnioni file 
          deserializeJson(doc, message);
          JsonObject obj = doc.as<JsonObject>();

          TI = obj[String(F("ti"))];
          DT02 = obj[String(F("dt02"))];
          TAG = obj[String(F("tag"))];
          TAH = obj[String(F("tah"))];

          if (obj[String(F("rsv"))] == 1){
            cmdRSV = 1;
          } else{
            cmdRSV = 0;
          }
          
          if (obj[String(F("rpv"))] == 1){
            cmdRPV = 1;
          } else{
            cmdRPV = 0;
          }
      }
      lastMillis2 = millis();

    }
}


void scriviWEB(){
    int pin= 0;
    String a= F("mqtt");
    String b= F("v1/.../things/.../data/");
    bool Tscd = false;
    // Pubbliacazione a tempo
    
    if ((millis() - lastMillis) > (60000)) {
        lastMillis = millis();
        Tscd = true;
        // Pubbliaca tamperature
        pin= 0;
        while (pin<4){
          if ((T[pin]-floor(T[pin])) < 0.5 ){
            T[pin]=floor(T[pin]);
          } else {
            T[pin]=floor(T[pin]) + 0.5;
          }
          Ciao.write(a, (b + pin), String(T[pin]));
          pin = pin + 1;
        }
        Ciao.write(a, (b + String(56)), String(millis()));
    }

    
    // Pubblia uscite
    pin = 1;
    while (pin<6){
      if ((O[pin] != Oold[pin]) || Tscd){
        Oold[pin] = O[pin];
        Ciao.write(a, (b + String(10+pin)), String(O[pin]));
      }
      pin = pin + 1;
    }

    
    // Pubblia ingressi
    pin = 1;
    while (pin<2){
      if ((I[pin] != Iold[pin]) || Tscd){
        Iold[pin] = I[pin];      
        Ciao.write(a, (b + String(20+pin)), String(I[pin]));
      }
      pin = pin + 1;
    }
}

void leggiINPUT() {
  I[1] = !mcp1.digitalRead(8);
  I[2] = !mcp1.digitalRead(9);
  I[3] = !mcp1.digitalRead(10);
  I[4] = !mcp1.digitalRead(11);
  I[5] = !mcp1.digitalRead(12);
  I[6] = !mcp1.digitalRead(13);
  I[7] = !mcp1.digitalRead(14);
  I[8] = !mcp1.digitalRead(15);
}

void leggiTEMP() {
  float a = 500.00;
  float b = 501.00;
  float emin = -10.00;
  float emax = 120.00;
  int pin = 0;
  
  while (pin<4){
       
  if (pin == 1) { T[pin] = ((Temperatura(pin) * 0.9) + (T[pin] * a) ) / b;  }  else {T[pin] = (Temperatura(pin) + (T[pin] * a) ) / b; }
      if ((T[pin] > emax) || (T[pin] < emin)) { eT[pin]= true; } else { eT[pin]= false;}
      pin = pin + 1;
  }
}
void scriviUSCITE() {
  mcp1.digitalWrite(7, O[1]);
  mcp1.digitalWrite(6, O[2]);
  mcp1.digitalWrite(5, O[3]);
  mcp1.digitalWrite(4, O[4]);
  mcp1.digitalWrite(3, O[5]);
  mcp1.digitalWrite(2, O[6]);
  mcp1.digitalWrite(1, O[7]);
  mcp1.digitalWrite(0, O[8]);
}



int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}



float Temperatura (int ThermistorPin) {
      //int ThermistorPin = 0; numero ingresso
      float Vo; // Integer value of voltage reading
      float Vs= 5; //Tensione di alimentazione termistrore
      float R = 10000.0; // Fixed resistance in the voltage divider
      float logRt,Rt,T,Vl;
      float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
      Vo = ( (float)analogRead(ThermistorPin)*5/1023 );
      Rt = R*( Vs / Vo - 1.0 );
      logRt = log(Rt);
      T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;
      return T;
}


void stufaLEGNA() {
// antigelo con sensore stufa legna
  if ((T[0] < TAG) && !eT[0]){ 
     M[2] = true;
  }
  if ((T[0]  > (TAG + TI)) || eT[0]){
     M[2] = false;
  }
  
// Comdo pompa stufa a legna

  if (((T[0] - T[2]) > DT02)  || (M[2])){
     O[1] = true;
  }
  
  if ((T[0] - T[2]) < (DT02 - TI)){
     O[1] = false;
  }

  //gestione sonde rotte
  if (eT[0] || eT[2] || (T[0] < TMinLegna)) {
     O[1] = false;
  }
}

void caldaiaGAS() {
// Comdo caldaia a gas
  if (T[3] < TAH){
     O[4] = true;
  }
  
  if (T[3]  > (TAH + TI)) {
     O[4] = false;
  }
  //gestione sonde rotte
  if (eT[3]) {
     O[4] = false;
  }
}


void riscaldamento() {
  
  if ((T[0] < TAG) && !eT[0]){ // antigelo con sensore stufa a legna
     M[0] = true;
  }
  if ((T[0]  > (TAG + TI)) || eT[0]){
     M[0] = false;
  }

  // Pompa scalda salviette
  O[2] = (I[1] && cmdRSV) || M[0];

  // Pompa riscaldamento a pavimento
  O[3] = (I[1] && cmdRPV) || M[0];
}


void pompaSolare() {
// antigelo con sensore solare
  if ((T[1] < TAG) && !eT[1]){ 
     M[1] = true;
  }
  if ((T[1]  > (TAG + TI)) || eT[1]){
     M[1] = false;
  }
  
// Comdo pompa pompa pannelli solari

  if (((T[1] - T[2]) > DT02)  || M[1]){
     O[5] = true;
  }
  
  if (((T[1] - T[2]) < (DT02 - TI))) {
     O[5] = false;
  }
  //gestione sonde rotte
  if (eT[1] || eT[2]) {
     O[5] = false;
  }

}

Thanks for your help.

1 Like

Just wanted to let you know I didn’t forget about you, just been really busy lately. I found my Industrial 101 and should be able to test in the next day or two.

1 Like

@fm1982

Maybe you can help me out here. I can’t find much info on google about this problem. When I try to open the Ciao config I get an error “Ciao library not found. Do you want to install it?”, but if I try to install it I get another error “Failed to scan directory: AJAX/XHR Error: 500”.

image
image

I got that figured out. Apparently I had installed a bunch of packages and it was just out of space. I did a factory reset on it and everything is back to normal.

After all that, it occurred to me. Are you wanting to get button presses from the dashboard, or read values from widgets? If you want to read values from widgets then unfortunately there is no way to achieve this since the retain flag has not been set on the Cayenne MQTT server.

thanks Adam
sorry if I didn’t help you.
I want to read the value of the widget.
How can I set the conservation flag?

regards.