Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webservice C# JSON to Arduino

I have a project in Microsoft Visual Studio C# and I have to send JSON data to my Arduino via Ehternet Shield.

This is how it works:
enter image description here

Is it possible? How to do it?

like image 355
Lugarini Avatar asked Sep 23 '14 23:09

Lugarini


3 Answers

Yes. You can do that.

There are some Arduino JSON libraries

  • Arduino JSON
  • aJSON
  • json-arduino

There are some difference between them, one is the Memory allocation (dynamically allocated for aJSON and json-arduino, and static for Arduino JSON).

I only used Arduino JSON, I was convinced by the GitHub documentation and comparison. Remember Arduino has almost no memory, so you should avoid sending big JSON messages, but if the message is like the one in the image, you shouldn't have any memory issue.

{"led":"255,255,255","tv":"on","air":"32"}

You can do a very decent WS client just following and "merging" these two tutorials:

  • Create a WS client
  • JSON Parser

Good luck!

like image 159
Gonza Avatar answered Oct 17 '22 05:10

Gonza


You could grab the http request when it arrives on the arduino and manually parse the request to get the json key/values. This probably is a little bit more work than just using a library, however you could save quite some memory by not having to include an entire library. As I have no idea what kind of other code is running on your arduino, and if you're using an UNO or a Mega, you might need the extra available memory. If memory is no issue, take a look at Gonza's answer!

Good Luck!

like image 29
Timmynator0 Avatar answered Oct 17 '22 05:10

Timmynator0


I just want to suggest to you what in the Arduino JSON parsing could be very slow because the device (Arduinio Uno) Clock Speed is only 16 MHz and the memory is only 32 KB. So, you must consider using a simple text response, using something like "substring" in a Pipe separated values.

Response example

like image 1
wrivas Avatar answered Oct 17 '22 06:10

wrivas