Show Posts
Pages: 1 [2] 3
16  Using Arduino / Networking, Protocols, and Devices / Re: Changes to external ip on: January 10, 2013, 06:42:53 pm
Put this php script to a server on Internet with know ip:

print ('<'.$_SERVER['REMOTE_ADDR'].'>');

And use something like this script to read the ip from there:

Now you just need to compare the new and old ip values.

Is this what you are looking for?
17  Topics / Home Automation and Networked Objects / Re: LAN server without refreshing on: January 10, 2013, 12:39:31 pm
I'm not sure but has the String been fixed yet?

Could it be that?
18  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 10, 2013, 12:08:28 pm
From what I've read polling causes an increase of the use of bandwidth which could affect other users, and it's not in real time so, it is still an option but not the best.

You are polling the server with a 8 bit 16 MHz machine. Even if you would have hundreds of them looping as fast as they can the web server will not be your bottleneck. If it is, drop the HTTP or even the TCP because the headers are most of the messaging.
19  Topics / Home Automation and Networked Objects / Re: Cheap and small RF Rx/Tx on: January 10, 2013, 09:45:30 am
There is a library called "VirtualWire" that adds framing around your message so that it can detect interference.  This can be used to prevent damaged messages from causing unexpected behavior on the receiver.

Documentation for VirtualWire can be found here:

This migth help also: You could use the same protocol and use those kinds of remotes to controll it along with your arduino.
20  Using Arduino / Programming Questions / Re: Text Array on: January 08, 2013, 03:56:03 pm
And the second question?

Absolutely anything can happen, horrible nondeterministic things eg. nasal demon will fly out.
21  Topics / Home Automation and Networked Objects / Re: Sensors on: January 08, 2013, 10:30:43 am
I use something I made myself.

On the center I have ground and +5v lines and the rest of the pins are freely routable with short jumper wires.

You can also rearrange the pins on the other end of the 3 or 4 wire cable with dupoint connectors you are using to connect the sensor, so this works with any sensor that requires 5v and 1 or 2 other IO pins. I have also added some extra +5v and ground pins to the other end of the proto board.

22  Using Arduino / Programming Questions / Re: Text Array on: January 08, 2013, 10:08:16 am
char sNames[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sun"};

What does that actually do? And specifically, what does it do if the number of characters in an initialiser string is not 3?

That would create a matrix like this
23  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 08, 2013, 08:38:16 am
Here is your code. I had to install new LAMP set up and while making sure everything works I wrote the example for you:

Arduino sketch modified from Ethernet WebClient example:
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress server(192,168,0,12); // Your webserver IP

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
  // give the Ethernet shield a second to initialize:


void loop()

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.println("GET /led/ledstatus.php HTTP/1.0");
    char c;
    // go trough the responce. as the value we are looking for is in the end of the responce after this loop char c will contain the last char of the respoce, 0 or 1
    while (client.available()) {
      c =;
    // if char c converted to an integer is somethning else than 0
    if (atoi(&c)) {
          Serial.println("Led should be on");
          //turn the led on here
           Serial.println("Led should be off");
           //turn the led off here
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  // if the server's disconnected, stop the client:
  if (!client.connected()) {

if (isset($_POST['status'])) {
    $fh = fopen("ledstatus.txt", 'w') or die("can't open file");
    $on = $_POST['status'];
    fwrite($fh, $on);

} else {
    $fh = fopen("ledstatus.txt", 'r');
    $on = fread($fh, 1);
<form action="index.php" method="post">
    <label> <input type="radio" name="status" <?if ($on) {echo 'checked = "checked"';} ?> value="1">On</label>
    <label> <input type="radio" name="status" <?if (!$on) {echo 'checked = "checked"';} ?> value="0">Off</label>
    <input type="submit" value="Submit">

    $fh = fopen("ledstatus.txt", 'r');
    echo fread($fh, 1);
24  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 08, 2013, 05:27:38 am
Actually, it's possible to get an arduino to do almost anything on the web.  Ever since plugins became possible (yes, I know it was years and years ago) we could simply 'include' source from an external source.  Just using an iframe we can put an entire web page on the browser with only a few bytes on the arduino.  Heck, we could put almost everything on a web server, and a little src=http://somebigserver/mypage to get it on the user's browser.

I use this little trick to get cool gauges and really big graphs on my little arduino web page.

I'm not sure was this comment for me. If it was, did you notice on my solution Arduino is doing a full CRUD (create, read, update delete) using a JSON Restinterface pretty much atomatically? It is not just loading files from the Internet to the browser.

25  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 07, 2013, 03:57:33 pm
Also, this is a little arduino with very limited capabilities when compared to a web server with all the supporting software they carry.  So, you don't have php, java, or any of that stuff to do work for you.  If you want to get a variable, you have to do it yourself in the arduino code.  This is normally done by constructing a string that indicates what you did and sending it back to the server.

Actually you can do quite a lot if you have an Arduino Mega 2560. I have been working on this lately and wrote a quick seminar paper for school about the subject. You can read the online version here but as it has been already two months since I wrote that the examples are out dated. How ever I have updated all the examples to GitHub to work with the current versions of the libraries.

All of the following examples also contain a link to dummy UI where you can try out how the UI works. If you are using Chrome open up the developer tools and pay attention what happens on the Network tab. None of these should be thought as real "projects" but instead of just demos. I haven't actually tested do even some of them work properly on all situations and the code is crappy.

The most simple one:

Most advanced:


PS. I just realized I spent many hours reading your blog after stumbling across it while googling yesterday.
26  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 07, 2013, 02:15:26 pm
The functionality you are after would in theory require websockets, but you will probably have do with polling.

On Arduino side you will have a loop that will keep making HTTP GET reguests to a url, lets say The "" is the IP address of your web server.

The ledstatus.php shoud serve some kind of responce. In your case it's enough to respond with a number 0 or 1 for on and off state. Read and parse the responce on Arduino and set the led on or off accordingly. The ledstatus.php should read the state from a txt file. It could be ledstatus.txt. Test the ledstastus.php with your browser to make it sure it works the way it should be.

On the server running on the ip you will have php page containing a html form, lets say index.php. The form should have two radio buttons with options: "on" and "off", and button to submit the form.  When the index.php page loads set the correct radio button selected according to value saved to a ledstatus.txt using php. Point the form action to formhandler.php.

The formhandler.php should first read the form parameter then save it to the ledstatus.txt file and then point the browser back to the index.php. You can also combine the formhandler.php and index.php into one file if you first check if the form parameter has been set and save the state if it is found.
27  Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs) on: January 05, 2013, 07:45:56 am
I made a another example.

This time the UI is controlling RC switches like these:

  • Controll cheap 433mHz AC switches with arduino and web UI
  • No computer needed as a mediator
  • Multipurpose JSON REST interface
  • Teach devices to arduino by pushing the remote controller buttons
  • Remote controller actions are tracked by the arduino
  • Timers
  • Settings saved to a SD card

Dummy test UI:

28  Using Arduino / Programming Questions / Re: Adding token to end of URL on: December 21, 2012, 01:41:32 pm
For simple GET/POST parameter handling you will probably do with the Webuino library

Use unix style timestamps. JavaScript date object will be your friend.

I just wrote an examle how a pins high/low state can be controlled using a web interface but it doesn't have the timer functionality you are after.

29  Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs) on: December 19, 2012, 04:44:44 am
Would it be possible to have an example about how to manage some of the PIN's status (something like ON/OFF).

I have an 8-channel relay board and I have been planning to write an example how it could be used as a timer controlled by a web gui. I'll send you a pm once I get it done and uploaded to github.

Thanks a lot !!!

I'm sorry that it has taken so long.

Here is a simple example how to control LOW/HIGH status of a pin.

Settings are saved after eatch change and loaded when the progrmam starts.

#include "SPI.h"
#include "Ethernet.h"
#include "SD.h"
#include "aJSON.h"
#include "WebServer.h"

//define range of pins you want to control
#define FROM_PIN 55
#define TO_PIN 58

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

WebServer webserver("", 80);
aJsonObject* pins;
File file;

void indexCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) {
if (type != WebServer::HEAD) {
P(helloMsg) =
"<!DOCTYPE html>\n<html lang=\"en\">\n"
"\t<meta charset=\"utf-8\">\n"
"\t<title>Pin Toggle</title>\n"
"\t<link href=\"\" rel=\"stylesheet\">\n"
"\t<link href=\',300\' rel=\'stylesheet\' type=\'text/css\'/>\n"
"<div class=\"container\">\n"
"\t<div id=\"pin-list\">\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n"
"<script src=\"\"></script>\n</body>\n"

// this method is performed before the reguest is prosessessed and default responce is generated
// server.setPreventDefault(true); disables the default prosessing and responce once
void switchBeforeResposeCmd(WebServer &server, WebServer::ConnectionType type, char * tail, bool tailComplete,
aJsonObject ** collection, aJsonObject ** model) {
if (type == WebServer::PUT) {
if (model != NULL) {
pinMode(aJson.getObjectItem(*model, "pin")->valueint, (bool) aJson.getObjectItem(*model, "low")->valuebool);


// this method is performed after the responce is sent so it doens't block it anymore
void switchAfterResposeCmd(WebServer::ConnectionType type, aJsonObject ** collection, aJsonObject ** model) {
pinMode(53, OUTPUT);

if (SD.exists("pin.txt")) {

file ="pin.txt", FILE_WRITE);
aJson.print(&**collection, file);

void setup() {
pinMode(53, OUTPUT);

if (!SD.begin(4)) {
Serial.println("SD initialization failed!");

if (SD.exists("pin.txt")) { //load settings file if found
file ="pin.txt");
pins = aJson.parse(file);

aJsonObject* current = pins->child;

while (current) {
pinMode(aJson.getObjectItem(current, "pin")->valueint,
(bool) aJson.getObjectItem(current, "low")->valuebool);
current = current->next;

} else { //if not found populate dta
pins = aJson.createArray();

for (int i = FROM_PIN; i < TO_PIN + 1; i++) {
pinMode(i, LOW);
pinMode(i, OUTPUT);
aJsonObject* pin = aJson.createObject();
aJson.addItemToObject(pin, "id", aJson.createItem(i - FROM_PIN + 1));
aJson.addItemToObject(pin, "pin", aJson.createItem(i));
aJson.addItemToObject(pin, "low", aJson.createItem(false));
aJson.addItemToArray(pins, pin);

//add binding to webserver and set actions
webserver.addJSONBinding("pins", &pins);
webserver.setBeforeRequest("pins", &switchBeforeResposeCmd);
webserver.setAfterRequest("pins", &switchAfterResposeCmd);



for (byte i = 0; i < 4; i++) {
if (i < 3) {

void loop() {

Dummy UI:
30  Using Arduino / Interfacing w/ Software on the Computer / Re: Question about: Arduino control over the Internet on: November 05, 2012, 02:31:00 am,129122.0.html
Pages: 1 [2] 3