Byte array as input to function

I am trying to get diferent readings from a NPK_sensor. To do this I build a function that uses the bytes to comunicate with the sensor. Using SoftwareSerial I need to send three diferent chains of bytes. The code compiles but shows warnings and notes. I have not been able to test the code because Im waiting for a 12V power suply to use the sensor. Anyway I would like to know if what imtrying to do is posible.

The warnings are the following

warning: invalid conversion from 'const byte* {aka const unsigned char*}' to 'byte* {aka unsigned char*}' [-fpermissive]
N = npk_read(NREQUEST,sizeof(NREQUEST));
note: initializing argument 1 of 'int npk_read(byte*, int)' int npk_read(byte request[8],int request_size){

This are the relevant parts of my code:

#include <SoftwareSerial.h>

SoftwareSerial npk_serial(RO,DI);
const byte NREQUEST[] = {0x01,0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};

byte soil_values[8];
void setup() {
npk_serial.begin(9600);
}
void loop(){
N = npk_read(NREQUEST,sizeof(NREQUEST));
}
int npk_read(byte request[8],int request_size){
  int reading;
  digitalWrite(DE,HIGH);
  digitalWrite(RE,HIGH);
  delay(10);
  if(npk_serial.write(request,request_size)==8){
    digitalWrite(DE,LOW);
    digitalWrite(RE,LOW);
    for(byte i=0;i<request_size;i++){
    soil_values[i] = npk_serial.read();
    }
    if(CHECKRESPONSE[0] == soil_values[0] && CHECKRESPONSE[1]== soil_values[1] && CHECKRESPONSE[2]== soil_values[2] ){
      reading= int(soil_values[3])+int(soil_values[4]);
    }
    else{
      reading = 9999;
    }
  }
  return reading;
}

Please copy and paste the entire error message listing, not just an excerpt.

Also please don't post only "the relevant parts of your code". Post the entire sketch.

Remove const from that definition.

Or add const to the function parameter

int npk_read(const byte request[8],int request_size){
1 Like

Why ?
I dont see the need for you to see the names of my folders, neither of including a huge amount of code which has nothing to do with the question.
If you want to see my work is all on my github I use the same username as here

Most of the time the issue is in the code that is not posted - so that’s why you got this request - but in your case there was enough information

Really ?? Ever heard of text editors? Did you know that you can use them to edit the requested output before posting it here?

Sorry but I had to get this of my chest.

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