1

I have a project to collect a html web page and convert it to a set of strings to be printed. I use arduino IDE to code this application, so java and other solutions do not work as it has to be accepted by arduino IDE. The char array has to be used to collect the incoming characters, but to store the results I need a string. These strings need to be able to take all characters including end of line, carriage return and tab. Html does not use zero characters so, the string can still be terminated correctly.

I have tried to put a zero char at the end of the received string in the char array, but the string still comes out as zero length. I have looked through ardunio.cc and this website, but all the answers are how to convert strings into arrays or are commented that this question has been asked before and NOT answered. This question has not been answered in valid arduino code as even writing a routine that adds individual chars to a string passes the compiler, but does not produce a string when run!

String tempStr = "";
int count2 = 0;

char message[700];

for (int count = 0; count < htmlpage.length(); count++) // maximum string length
{
      bufferchr =0;
      bufferchr = (htmlpage.charAt(count2+lencount1));
      message[count2] = bufferchr;
      count2 = count2 +1;
}
tempStr = chararryToStr(message); // fails
tempStr=(message);   // also fails

Count does not exist outside the loop, its value is zero. I have included count2 to measure the length of the resulting string in the message array.

All of the string contents come out as zero length, where as printing the char array shows the true results.

This Answers fails to compile on Arduino Uno and gives the following errors which are all down to the arduino core programming not accepting the suggested code. Arduino: 1.8.8 (Windows 8.1), Board: "Arduino/Genuino Uno" ead_string_arduino:69:11: error: no match for 'operator=' (operand types are 'String' and 'String*') tempStr = new String (message); // cast it to string zero length ^ In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:222:0, from C:\Users\stephen\AppData\Local\Temp\arduino_build_685202\sketch\read_string_arduino.ino.cpp:1: C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:86:11: note: candidate: String& String::operator=(const String&) String & operator = (const String &rhs); ^ C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:86:11: note: no known conversion for argument 1 from 'String*' to 'const String&' C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:87:11: note: candidate: String& String::operator=(const char*) String & operator = (const char cstr); ^ C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:87:11: note: no known conversion for argument 1 from 'String' to 'const char*' C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:88:11: note: candidate: String& String::operator=(const __FlashStringHelper*) String & operator = (const __FlashStringHelper str); ^ C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:88:11: note: no known conversion for argument 1 from 'String' to 'const __FlashStringHelper*' exit status 1 no match for 'operator=' (operand types are 'String' and 'String*')

0

1 Answer 1

0

There is no declaration for lencount1 so not exactly sure what your code is doing, but regardless, it's way too complicated.

First, to copy out a C++ String to a C array, there are multiple ways to do this, but strncpy(message, html.c_str(), sizeof (message));

is probably the simplest.

To copy a C++ string into another C++ string, and assuming htmlpage is a String too, then you just need tempStr = htmlpage;

3
  • unfortunately I have already tried this and you cannot turn the c++ array into a string as Arduino makes it a constant, read only object. You also cannot print it or send it a serial device that only accepts strings. This a Arduino question, not a C++ question Commented May 1, 2019 at 8:20
  • Arduino IS C++. That's what lies below the veneer. There is no indication from the original question what "htmlpage" is. Regardless, yes, you can turn C++ array to a string. You may have to "extract" the pointer and use more than a simple '=' operation, but it is doable. For best result though, we do need to see the declaration of htmlpage Commented May 2, 2019 at 20:29
  • It was too long to include, but here is a small sample. "<!DOCTYPE html>\n<!--[if IE 7 ]><p class=\"fastfree translation--welsh\"><\p>\n<form id=\"reg_form\"" . \ is escape char needed to include some characters in a string. Commented May 6, 2019 at 12:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.