Having trouble compiling code on Spark that works on Arduino

Hello,

The code below won’t compile but does work on a Arduino.

The compiler give’s me the error: undefined reference to `String::operator=(String&&)’ on line T181 = line.substring. T181 is globally defined as String.

Can someone tell me what is wrong?

  void parseLine(String line) {
  
    String OBISref = line.substring(4,9);
    posAstrix = line.indexOf("*");
  
    if ((OBISref == "1.8.1") and (posAstrix > -1)) {
      T181 = line.substring(10, posAstrix);
    }
  }

Kind regards,
Jacco

Hi @jacco - happy to help although it’s difficult to debug compile issues without the full code. Can you boil your code down to a short snippet that can be copy-pasted into the IDE that you expect to compile but will not?

Hi Zach,

Below the full code:

const int requestPin =  4;
char c;

#define INPUT_BUFFER_SIZE          128  // Buffer waar de karakters van de seriele poort in worden opgeslagen.
char InputBuffer_Serial[INPUT_BUFFER_SIZE+2];
int SerialInByteCounter=0;
int posAstrix;
String T181;
boolean messageBegin;
boolean messageEnd;

void setup() {
  Serial.begin(115200);   // USB, Virtual COM port
  Serial1.begin(9600);  // RX, TX port
  SerialInByteCounter = 0;
  messageBegin = false;
  messageEnd = false;
  Serial.println("P1 DSMR logger");
  Serial.println("Protocol: NEN-EN-IEC 62056-21 Mode D");
  Serial.println("Activate RTS...");
  pinMode(requestPin, OUTPUT);
  digitalWrite(requestPin, HIGH);
  Serial.println();
}

void loop() {
  if (Serial1.available()) {
      while (Serial1.available() > 0) {
        c = Serial1.read();
       
        // --- 7 bits instelling ---
        c &= ~(1 << 7);
        char inChar = (char)c;
        // --- 7 bits instelling ---
        Serial.print(c);// echo ontvangen teken
    
        if(isprint(inChar)) {
          if (SerialInByteCounter < INPUT_BUFFER_SIZE) // alleen tekens aan de string toevoegen als deze nog in de buffer past.
              InputBuffer_Serial[SerialInByteCounter++] = inChar;
        }
        
        if (not (messageBegin) and (SerialInByteCounter == 1) and (inChar == '/')) messageBegin = true;
        if (not (messageEnd) and (SerialInByteCounter == 1) and (inChar == '!')) messageEnd = true;
        
       
        if(inChar=='\r' || inChar=='\n') {
          InputBuffer_Serial[SerialInByteCounter]=0; // serieel ontvangen regel is compleet
          parseLine(InputBuffer_Serial);          
          SerialInByteCounter=0;
          InputBuffer_Serial[0]=0; // serieel ontvangen regel is verwerkt. String leegmaken
        }
     }  
  }
  
  if ((messageBegin) and (messageEnd)) {
    messageBegin = false;
    messageEnd = false;
    printObjects();
  }  
  
}

void parseLine(String line) {

  String OBISref = line.substring(4,9);
  posAstrix = line.indexOf("*");
  
  if ((OBISref == "1.8.1") and (posAstrix > -1)) {
    T181 = line.substring(10, posAstrix);
  }
  else {
    if ((OBISref == "1.8.2") and (posAstrix > -1)) {
      //T182 = line.substring(10, posAstrix);
    }
  }    
}

void printObjects() {
  Serial.println("----------------------------------------------------------------");      
  Serial.println("Elektriciteitsstand geleverd laagtarief:         " + T181);  
  Serial.println("----------------------------------------------------------------");    
}

Thanks,
Jacco

Hmm, super weird. Not sure why that’s not compiling, it seems to be getting the typing confused. I’ve found a workaround that will help in the short term. Try this:

String temp = line.substring(10, posAstrix);
T181 = temp;

I’m also adding this to the backlog to see that the issue gets resolved in the long run:

Thanks for the workaround Zach…I can live with this.

Regards,
Jacco

As a general comment, I have found the Core to be very specific in its arduino code requirements. That is, code that runs perfectly fine on an arduino will require some slight modification to properly run on the Core. As an example. I had an arduino sketch which used an IR proximity sensor to pulse LEDs below a specified threshold. On the arduino side, I hadn’t designated the digital pins to which the LEDs were connected as OUTPUT, yet the application ran perfectly fine. When I moved the code to the Core, the WebIDE required the digital pins to be set as OUTPUT, otherwise the app wouldn’t compile.

If anything, I suppose that’s a good thing as it taught me to be more explicit in my coding practices, but yes, I have noticed a slight difference between arduino and the Core.

@gaudsend Thanks for the feedback! Our goal is definitely to make transitioning between the Core and Arduino’s hardware as seamless as possible. Since the boards are based on different chipsets, though, it will take some help from the community to discover all the holes that need to be patched :smile:

If you have any other specific issues that we can add to our backlog for future improvement, we’d be happy to work on them to improve the experience of developing on the Core.

1 Like

Same problem with this library https://github.com/nmattisson/HttpClient, it compiles outside the IDE but I’m getting the same error when I try on the IDE.
It would be awesome to have this library running on the core :smile:

I’ve also seen this problem, and it only seems to be an issue when compiling on the web IDE. compiles fine locally.

I had the same problem today and @zach suggestion worked.

I’m also having same issue with String data type. The temporary solution provided by @zach works but that requires to declare additional variable using additional memory. Can there be a permanent fix please? Thanks!