Introduction: Arduino Wifi Redback Webserver Example

About: I am an electrical engineer and an Arduino and electronics enthusiasts. I believe working with electricity should be fun as well as beneficial to engineers and the world at large. Twitter handle: @arduinohack…

An arduino wifi Redback can be used as a webserver. The wifi redback webserver example available in the CuHead library perfectly shows us how to do this. I am going to walk you through it so that you can understand it better.

Step 1: Getting Started

Start the arduino IDE and click on Files>Examples>Cuhead>Webserver. If you cannot see the CuHead library in your examples menu, please check my previous tutorial on setting up the Wifi Redback so that you can know how to download and set up the library.

You will realize that the arduino webserver example does not compile at first. Do not get scared, because there is a simple solution to that. All you need to do is edit the application configuration file apps-conf.H in the CuHead library so as to include the header file for the webserver application. Here is how it’s done.
Open the apps-conf.H file. In my computer it is located here: C:\Program Files (x86)\Arduino\libraries\CuHead\apps-conf.H

Uncomment the #define APP_WEBSERVER statement by deleting the // before the statement. Comment out the #define APP_WISERVER by adding // before the statement. Save once you are done, then go back to the Webserver example and compile it. If you have done it correctly, the code will compile successfully.

Step 2: Editing the Code

The redback Webserver example does not work automatically. You have to edit the wireless configuration parameters to match those of your router. For instance, I was using my phone as router by making it a portable wifi hotspot. So I had to change the wireless configuration parameters on the webserver example to:

// Wireless configuration parameters —————————————-

unsigned char local_ip[] = {192,168,43,2}; // IP address of WiShield

unsigned char gateway_ip[] = {192,168,43,1}; // router or gateway IP address

unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network

const prog_char ssid[] PROGMEM = {“yhtomit”}; // max 32 bytes. Hotspot name

unsigned char security_type = 0; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

The IP address of my phone’s wifi hotspot is 192.168.43.1 . So that is what I used as the gateway IP address and I also changed the SSID to yhtomit which is the SSID of my phone’s wifi hotspot.
In the first instance I left the security type as 0 since my hotspot was open. If your router requires a password, find out which security protocol it uses i.e. WEP, WPA or WPA2 and then change the security type value to match your security protocol.

In the second instance I changed the security protocol of my portable hotspot to WPA2 and changed the security type to 3 on the webserver code. I didn’t have to change the WPA passphrase since I had set it to12345678 on my phone,just like in the webserver example. However, if your network has a different key, say 11447 change the passphrase to that value by editing this line:

// WPA/WPA2

passphrase const prog_char security_passphrase[] PROGMEM = {“12345678″}; // max 64 characters

to

// WPA/WPA2 passphrase const prog_char security_passphrase[] PROGMEM = {“11447″}; // max 64 characters

Unfortunately I did not get to test the WEP configuration, but I will do that another time and update the post.

Step 3: Uploading Code

After you have changed the wireless settings to match your router’s settings and pretty much done everything explained above, upload the code onto your arduino wifi redback. The TX and RX LEDs on the FT232RL board will flicker, same to the digital I/O LED.

Give the redback a little more time, for the wifi module to be setup, and the wifi LED will glow solid green. This means that the Wifi module has connected to your router. To prove this, go to your web browser and type the wifi redback IP address onto the address bar (in my case, I typed it on my phone’s internet browser) and voila! A web page will appear on your browser with a Hello world message.

That is pretty much it. You can edit the arduino wifi redback webserver example to fit your project needs. I am going to do a small project soon to show you how you can implement this code in a project. Meanwhile you can check out the following related posts:

Setting up the arduino wifi redback

This article was posted on www.arduino-hacks.com