No matching function for call to 'CairsensUART::CairsensUART()

Hi everyone,

I am using my Arduino MKRWifi 1010 with serial interface on Cairsens sensor.
I used Cairsens Library : GitHub - Lahorde/cairsens_uart: CairPol Cairsens UART protocol

But It didn't work, Could you help me?

My code:

#include <cairsens.h>

#include <SPI.h>
#include <WiFiNINA.h>


#include <ArduinoRS485.h>
#include <ArduinoModbus.h>


char ssid[] = "********";          // 
char pass[] = "******";  // 
int keyIndex = 0;

//Stream arg;

const int ledPin = 7;
/////////////////////////////////////////////////////////////////////////////////////////////////////
//#define arg;


CairsensUART cair;                              //creer un nouveau objet de classe CairsensUART


/////////////////////////////////////////////////////////////////////////////////////////////////////
int status = WL_IDLE_STATUS;

WiFiServer wifiServer(502);

ModbusTCPServer modbusTCPServer;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Modbus TCP Server LED");

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the status:
  printWifiStatus();

  // start the server
  wifiServer.begin();

  // start the Modbus TCP server
  if (!modbusTCPServer.begin()) {
    Serial.println("Failed to start Modbus TCP Server!");
    while (1);
  }

  // configure the LED
  pinMode(ledPin, OUTPUT);
  pinMode(13, INPUT);
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);

  pinMode(5, INPUT);


  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);


  modbusTCPServer.configureCoils(0x00, 1);

}

void loop() {
  WiFiClient client = wifiServer.available();

  if (client) {
    Serial.println("new client");

    modbusTCPServer.accept(client);

    while (client.connected()) {
      modbusTCPServer.poll();

     updateLED();


    }

    Serial.println("client disconnected");
  }
}

void updateLED() {
  // read the current value of the coil
  int coilValue = modbusTCPServer.coilRead(0x00);

  if (digitalRead(5) == LOW)
  {

    digitalWrite(7, HIGH);
  } else {

   digitalWrite(7, LOW);
  }
  if (coilValue) {

    digitalWrite(ledPin, HIGH);




    ////////////////////////////////////////////////////////////////////////////////////////


    //Serial.println(analogRead(getNO2InstantVal(int& arg_u8_val)));
    int a = analogRead(13);
    //Serial.println(cair.getNO2InstantVal(a));

int b= Serial1.read();
Serial.println(cair.getNO2InstantVal(b));



    
 

  } else {


    digitalWrite(ledPin, LOW);
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

And the errors:

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino MKR WiFi 1010"

step1:20:14: error: no matching function for call to 'CairsensUART::CairsensUART()'

CairsensUART cair; //creer un nouveau objet de classe CairsensUART

^~~~

In file included from D:\Anass_Sensor\step1\step1.ino:1:0:

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:123:5: note: candidate: CairsensUART::CairsensUART(Stream*)

CairsensUART(Stream* arg_p_uartStream);

^~~~~~~~~~~~

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:123:5: note: candidate expects 1 argument, 0 provided

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:49:7: note: candidate: constexpr CairsensUART::CairsensUART(const CairsensUART&)

class CairsensUART

^~~~~~~~~~~~

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:49:7: note: candidate expects 1 argument, 0 provided

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:49:7: note: candidate: constexpr CairsensUART::CairsensUART(CairsensUART&&)

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:49:7: note: candidate expects 1 argument, 0 provided

D:\Anass_Sensor\step1\step1.ino: In function 'void updateLED()':

step1:169:39: error: cannot bind non-const lvalue reference of type 'uint8_t& {aka unsigned char&}' to an rvalue of type 'uint8_t {aka unsigned char}'

Serial.println(cair.getNO2InstantVal(b));

^

In file included from D:\Anass_Sensor\step1\step1.ino:1:0:

C:\Users\Asus\OneDrive\Documents\Arduino\libraries\cairsens_uart/cairsens.h:134:12: note: initializing argument 1 of 'CairsensUART::EError CairsensUART::getNO2InstantVal(uint8_t&)'

EError getNO2InstantVal(uint8_t& arg_u8_val);

^~~~~~~~~~~~~~~~

exit status 1
no matching function for call to 'CairsensUART::CairsensUART()'

Thanks in advance

It looks like the constructor for the CairsensUART class requires that you pass it an argument that's a pointer to a Stream class object. Your code does not do this.

Thank you gfvalvo, It works and the compiling sketch did well .
However, I didn't get a result in Serial Monitor. (you can see the Attach)

Can you help me how can I get the value on pin 13 (RX, MKRWifi) ?

My new code:

#include <cairsens.h>

#include <SPI.h>
#include <WiFiNINA.h>


#include <ArduinoRS485.h>
#include <ArduinoModbus.h>


char ssid[] = "********";          //
char pass[] = "******";  //
int keyIndex = 0;

//Stream arg;

const int ledPin = 7;
/////////////////////////////////////////////////////////////////////////////////////////////////////
//#define arg;


CairsensUART cair(&Serial);                              //creer un nouveau objet de classe CairsensUART


/////////////////////////////////////////////////////////////////////////////////////////////////////
int status = WL_IDLE_STATUS;

WiFiServer wifiServer(502);

ModbusTCPServer modbusTCPServer;

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Modbus TCP Server LED");

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the status:
  printWifiStatus();

  // start the server
  wifiServer.begin();

  // start the Modbus TCP server
  if (!modbusTCPServer.begin()) {
    Serial.println("Failed to start Modbus TCP Server!");
    while (1);
  }

  // configure the LED
  pinMode(ledPin, OUTPUT);
  pinMode(13, INPUT);
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);

  pinMode(5, INPUT);


  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);


  modbusTCPServer.configureCoils(0x00, 1);

}

void loop() {
  WiFiClient client = wifiServer.available();

  if (client) {
    Serial.println("new client");

    modbusTCPServer.accept(client);

    while (client.connected()) {
      modbusTCPServer.poll();

     updateLED();


    }

    Serial.println("client disconnected");
  }
}

void updateLED() {
  // read the current value of the coil
  int coilValue = modbusTCPServer.coilRead(0x00);

  if (digitalRead(5) == LOW)
  {

    digitalWrite(7, HIGH);
  } else {

   digitalWrite(7, LOW);
  }
  if (coilValue) {

    digitalWrite(ledPin, HIGH);




    ////////////////////////////////////////////////////////////////////////////////////////


    uint8_t a = Serial1.read();
    Serial.println(cair.getNO2InstantVal(a));

////////////////////////////////////////////////////////////////////////////////////////////

  } else {


    digitalWrite(ledPin, LOW);
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Thanks in advance

I don't have the hardware nor that library installed. I only checked its source code on GitHub. You'll have to do some debugging.