Marco Schwartz created this tutorial on how to make a REST API for his Arduino Yun and the CC3000 WiFi chip, from openhomeautomation.
I was recently playing with the Arduino Yun for a whole set of new projects, and I discovered a sketch that implements a REST API for the Arduino Yun. We’ll see in more details what a REST API is, but for now let’s say it allows to standardise the communication between your Arduino and the external world via WiFi or Ethernet, and develop complex applications without having to modify your Arduino sketch every time.
So I told myself: why not create one REST API for the CC3000 WiFi chip ? That’s exactly what I did as a weekend project, and I wanted to share it with you. If you want to directly jump to the project files, go over to the GitHub repository of the project.
So what’s a REST API ?
You may wonder: what’s a REST API ? It’s actually a concept that is widely used by many web applications like SaaS. REST stands for Representational State Transfer, and is a communication architecture that was created back in 2000. It defines many constraints that the architecture has to follow, the most important features being:
- A client/server communication: a client sends a request to a server, and the server answers accordingly
- A stateless communication: every request has to contain all the information so the server can understand it, without having to rely on some information stored on the server
- A uniform interface to easily identify resources on the server
This allowed to standardise communication between web applications, and made them more scalable, faster, and simplified the development of more complex applications. Many applications now propose a REST API, for example the eCommerce plugin I am using on this website.
Why do we need it for Arduino & the CC3000 WiFi chip ?
The problem that I encountered while developing web applications using the CC3000 is that I had to create a new Arduino sketch for every application, that needs to be coordinated with the rest of the application, for example an interface running on my computer.
And then, I discovered the REST API of the Arduino Yun. It is a simple sketch for the Arduino Yun that allows to make REST calls directly from your browser. For example:
will put the pin number 8 to a high state on my Arduino Yun. With this REST interface, it’s easy to load a sketch once for all on your Arduino, and then only work on the interface on your computer that makes REST calls on your Arduino board. And for now, this kind of interface was only available on the official Arduino boards, like the WiFi & Ethernet shields, and the Yun.
But I wanted to have the same on my CC3000 WiFi chip: make a sketch that will create a web server on the Arduino board, and then accept REST commands from an external client, like from an interface running on my computer. With this, I just have to build complex web applications on my computer, and then made them interact with the REST API of my Arduino board. And that’s what I built in this project.
Featured Adafruit Products!
Arduino YUN (YÚN ): Arduino Yún is the first member of a new groundbreaking line of wifi products combining the power Linux with ease of use of Arduino. Yún means “cloud” in Chinese language as the purpose of this board is to make it simple to connect to complex web services directly from Arduino. The first Arduino Yún is the combination of a classic Arduino Leonardo (based on the Atmega32U4 processor) with a Wifi system-on-a-chip running Linino (a MIPS GNU/Linux based on OpenWRT). Read more!
Adafruit CC3000 WiFi Breakout with Onboard Ceramic Antenna – v1.1: The CC3000 hits that sweet spot of usability, price and capability. It uses SPI for communication (not UART!) so you can push data as fast as you want or as slow as you want. It has a proper interrupt system with IRQ pin so you can have asynchronous connections. It supports 802.11b/g, open/WEP/WPA/WPA2 security, TKIP & AES. A built in TCP/IP stack with a “BSD socket” interface. TCP and UDP in both client and server mode, up to 4 concurrent sockets. It does not support “AP” mode, it can connect to an access point but it cannot be an access point. Read more!
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!
Maker Business — TechShop is closed, files bankruptcy
Wearables — Get concrete solutions
Electronics — Are you grounded?
Biohacking — Learning to See with Sound
No comments yet.
Sorry, the comment form is closed at this time.