Conversion from 'int' to 'const String' is ambiguous on

With the help of 2 RF24 and EMONLIB libraries, I have created the following code, I have had an error when compiling in the receiver I have a transmitter where I send a string of separated characters, I receive the data in the receiver and see it in the port serial , I want to use a conditional with the variables received and when checking it gives me an error

error: conversion from 'int' to 'const String' is ambiguous

THIS CODE RX




#include <SPI.h>
#include <RH_NRF24.h>

RH_NRF24 nrf24;

String str_datos;
String str_voltage1;
String str_voltage2;

int contactor_S = 3;



void setup()
{

  Serial.begin(9600);
  while (!Serial);
  if (!nrf24.init())
    Serial.println("init failed");
  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!nrf24.setChannel(1))
    Serial.println("setChannel failed");
  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
    Serial.println("setRF failed");

  Serial.println("Receptor Iniciado");

  pinMode (contactor_S, OUTPUT);

}

void loop()
{
  uint8_t buf[13]; //7
  uint8_t buflen = sizeof(buf);

  if (nrf24.recv(buf, &buflen)) {

    str_datos = String ((char*)buf);

    for (int i = 0; i < str_datos.length(); i++) {
      if (str_datos.substring(i, i + 1) == ",") {
        str_voltage1 = str_datos.substring(0, i);
        str_voltage2 = str_datos.substring(i + 1);

        break;
      }
    }
    Serial.print("Voltage V1: ");
    Serial.println(str_voltage1);
    Serial.print("Voltage V2: ");
    Serial.println(str_voltage2);


    if ( (str_voltage1 >= 90)  &&  (str_voltage1 <= 135) ) /// ERROR!!!
    {
      digitalWrite(contactor_S, HIGH);
    }
  }
}

what will be happening ???

Hi,
try this way:

if ( (str_voltage1 >= "90") && (str_voltage1 <= "135") )

Or alternatively:

    if ( (str_voltage1.toInt() >= 90)  &&  
         (str_voltage1.toInt() <= 135) )
    {
1 Like

THANK YOU , johnwasser with this alternative it works

ruilviana, thank you..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.