Arduino JSON Web Server

I wrote a small program to implement a web server with a JSON/HTTP interface for accessing I/O pins on the Arduino.

Of course to use this you have to have an Ethernet shield (wired or WiFi) on your Arduino; a standard bare Arduino by itself has no network interface. But if you have the shield, then this software gives you a network-ready interface to the analog and digital I/O capabilities of the board.

You can, for example, do a GET on /v1/analogRead/5 to read pin 5 from your Arduino, or POST a JSON object to /v1/digitalWrite to set a pin HIGH or LOW, etc. See the README file at https://github.com/outofmbufs/arduino-json-IO for details and source code.

6 thoughts on “Arduino JSON Web Server”

  1. I tested the server by writing some code to send requests continuously. Over a period of roughly five days I sent more than 4 million requests to the server without any problem, so I declare the code as functioning and stable 🙂

  2. Great job, and a very neat code.
    I’ve started to write a similiar web server for arduino and came across your solution. If you don’t mind I will make some tests with your code?

  3. The code is made freely available so have at it!

    While I’m commenting on this thread … I should add that I have one report that the code didn’t work with a WiFi shield; I haven’t been able to verify that myself (I use it with the wired Ethernet shield). It shouldn’t matter, but maybe there is a memory footprint problem (just a guess).

    I’ve built two things using this code. One of them is monitoring a sensor on a piece of equipment in my house and has been running flawlessly for a few years now. The other was used recently as part of my Christmas lights LED project.

  4. Hi There,

    This code looks to be exactly what I need to set up some basic home lighting automation I’m working on.
    Forgive the potentially daft question, but what is the best way to implement this into my project? Do I need to install this code into my Arduino IDE somehow to be able to use it? Is it a case of putting the analogjson.ino file somewhere in particular in my filesystem and using an #include statement? I’m still fairly new to the Arduino IDE so I’m a little unsure to get going. Any help would be greatly appreciated.

  5. I have to admit I find this part of the IDE perplexing. Here’s one way to do it; I don’t doubt this probably isn’t the “best” way but it’s what I do.

    Start a new project in the IDE (File->New). Then SaveAs (File-SaveAs) the skeleton code it makes for you… I prefer at this point overriding the generic location it wants to put such things and putting them into “my” file tree. But you can put it anywhere. Make note of where it went.

    If you called the project “testproj” when you did the SaveAs, it will be testproj.ino in a subdirectory called testproj. For some reason the file name must match the containing directory name. Find the testproj.ino file. Replace it with analogjson.ino (i.e., copy analogjson.ino from github either via git clone, ZIP, or however you like to do that, and once the file is there rename it to testproj.ino because the name MUST MATCH the directory name). While you are doing this put jsmn.c and jsmn.h in the same directory.

    Now reopen the IDE and when you load this project you’ll be in business. Edit additional stuff into the loop() and setup() functions as needed.

    Anyone who wants to take this to another level and turn it into a real library with a better organizational structure knows where the code is on github 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *