Teensy 3.1 and TinyWebServer Library

Status
Not open for further replies.

braddo

Member
I'm working on a project to host a small web page and communicate with a sprinkler via AJAX. The example I'm working from uses the TinyWebServer library (https://github.com/ovidiucp/TinyWebServer).

There is an example in that library called WebServerSD, which has some configurations to serve files from the SD containing html/js/css etc. This example uses the Flash.h library.

When I compile the example with no modifications I get this error:
Code:
In file included from WebServerSD.ino:10:0:
C:\Users\X\Arduino\libraries\Flash/Flash.h: In member function 'char* _FLASH_STRING::copy(char*, size_t, size_t) const':
C:\Users\X\Arduino\libraries\Flash/Flash.h:78:37: error: operands to ?: have different types 'char*' and 'int'

BTW someone else posted this same issue last year January but no responses (http://forum.pjrc.com/threads/16951-T3-compile-error-flash-library)

The offending line from Flash.h appears to be this one (a few before and after):

Code:
/* _FLASH_STRING class.  Use the FLASH_STRING() macro to create these, or use inline F() macro. */
class _FLASH_STRING : public _Printable
{
public:
  _FLASH_STRING(const prog_char *arr);

  size_t length() const 
  { return strlen_P(_arr); }

  char *copy(char *to, size_t size = -1, size_t offset = 0) const 
  { 
    return size == -1 ?
      strcpy_P(to, _arr + offset) : strncpy_P(to, _arr + offset, size);    [B]<< Error points to this line[/B]
  }

  const prog_char *access() const 
  { return _arr; }

  const _Printable &Printable() const
  { return *this; }

  char operator[](int index) const
  { return static_cast<char>(pgm_read_byte(_arr + index)); }

  void print(Print &stream) const;

private:
  const prog_char *_arr;
};

Now I have seen lots of discussion about discrepancies between AVR and ARM C native types such as char, int etc, but am having trouble mapping the various things I've read to this particular problem.

It seems like Flash is a super common Arduino library, I'm wondering if there's already an ARMified Teensified version of it somewhere, but I didn't see it in the installer or any searching I've done. Also, bad luck, the original location of the Flash library http://arduiniana.org/libraries/flash/ is down at the moment, maybe there's an Arduino Due version that would just work?

Any thoughts? Just soldered up my T3.1 and Wiznet820io boards last night and eager to stop having out of memory crashes from the UNO, but not so happy to replace those with incompatibility errors here. Could have got a Teensy2 but took the chance, hopefully it can work!

TIA
 
The flash string macro, used like this:

Serial.println(F("hello world"));

works for both AVR and ARM forms of Teensy.

I've not needed to do any special #include to use it.
 
Well, for me, using Arduino 1.0.5r2, I get a compile error as above in the _FLASH_STRING class, which I guess F() is later aliased to FLASH_STRING

On further checking, I can get rid of the error above by changing the ternary operator into an if/else

Code:
if (size == -1) return strcpy_P(to, _arr + offset);
	else return strncpy_P(to, _arr + offset, size);

but now the error I get is:

Code:
 invalid conversion from 'int' to 'char*' [-fpermissive]

Not too familiar with strcpy and strncpy, but if I just return one or the other, strcpy compiles and strncpy does not.

Seems like strncpy is returning an int, an its calling function:

Code:
char *copy(char *to, size_t size = -1, size_t offset = 0) const {...}

is attempting and failing to coerce it to a char (?)
 
Are you suggesting that my include of Flash might be somehow overriding something Teensyduino has built in to take care of F()?

I could try that!
 
Are you suggesting that my include of Flash might be somehow overriding something Teensyduino has built in to take care of F()?

I could try that!
Yes. I use the F macro and Paul's clever code behind that macro, without #includes for it, nor any C/C++ code for it in my builds. It's in the libraries for T2 and T3.

strcpy_P() and strncopy_P() are old but still used and have nothing to do with Paul's macro.
And sscanf_P() and a few others. These are documented in the generic AVR libc docs; they're not Arduino or Teensy specific.

All this _P crud due to the AVR's Harvard architecture is one reason that I focus on using Teensy 3 and ARMs now.
 
Last edited:
Got it working

OK so in the end I just did this:

Code:
  void *copy(char *to, size_t size = -1, size_t offset = 0) const 
  { 
    if (size == -1) strcpy_P(to, _arr + offset);
	else strncpy_P(to, _arr + offset, size);
  }

I"m not sure why the function was trying to return a char in the first place.

the F() works now.

I'm still having some weirdness in that most of the setup() print statements aren't working, only the ones in module calls after setup.

If I'm very quick on the draw in popping the serial monitor I can get a few messages - I'm used to seeing everything. Is the serial device just too fast and they're gone before the window opens?







On further checking, I can get rid of the error above by changing the ternary operator into an if/else

Code:
if (size == -1) return strcpy_P(to, _arr + offset);
	else return strncpy_P(to, _arr + offset, size);

but now the error I get is:

Code:
 invalid conversion from 'int' to 'char*' [-fpermissive]
 
Last edited:
Status
Not open for further replies.
Back
Top