Diaoul / arduino-ESP8266

An Arduino library to manage the ESP8266.
MIT License
68 stars 46 forks source link

Templated send function #10

Closed jonathanchristison closed 9 years ago

jonathanchristison commented 9 years ago

I don't know if theres a specific reason why the send functions are limited to the few overloads provided? Currently the function deceleration is suggestive to use plaintext representation of primitive types i.e uint8_t would be represented by 3 or 4 characters { '2', '5', '5', '\0' }(at least it was to me, perhaps i missed something) or otherwise convert objects to character arrays.

This of course makes perfect sense when communicating in plain text between the ESP8266 and something like netcat, however M2M/binary data packets would be much easier to handle at both ends progmatically, It also reduces superfluous data. Im sure i've missed considerations of endianness but this was a quick hack as proof of concept, its unoptimised (it will currently call CIPSEND for each underlying type in an array) and its lacking a typed data reader, this again could be provided as a template overload). I'll try and add one in the next few days and a example if you think it will be useful?

Diaoul commented 9 years ago

It was a first implementation and enough to support the Client interface which is used by the MQTT client that I use so that was enough for me at least.

I think its sexier that way, thanks :)

Diaoul commented 9 years ago

Also, you could just send raw data by converting to uint8_t* and using sizeof(yourvariable) as size. Or maybe I'm missing something?

jonathanchristison commented 9 years ago

@Diaoul I didn't realise that I'll certainly look into MQTT, Its probably perfect for what I need to do (no point in reinventing the wheel)

You could of course convert it before the send() its just a bit easier to read wifi.send(obj) rather than wifi.send((uint8_t*)&obj, sizeof(obj))

Cheers