Close

Open for you to test!!

A project log for E-duino

An open source internet remote to control your arduino from anywhere

EtienneEtienne 03/08/2017 at 19:260 Comments

Here we go!!!

You can from now on create a new remote here, using the code 'hackaday'. Right after creating the remote, you'll be able to add inputs to it. The actual possible inputs are :

-Text : a simple text input, nothing special here

-Switch : A simple button that you can turn on and off, still very basic

-Slider : A slider with a default range of [0; 255], which can be modified with two arguments :

-min: the minimum value

-max : the maximum value

The slider uses jquery ui.

The possibility for users to create some inputs is the next thing on my list, but if you need one quickly, feel free to ask.


Here's the arduino code to control some leds witha slider and/or a button. You can find it in the files section too.

/*
 * Code written by Etienne Desrousseaux as an example for the e-duino project : 
 * https://hackaday.io/project/20088-e-duino
 * 
 * written on 08/03/2017
 * 
 * 
 * This example connects to a remote using an ethernet shield, downloads data from a slider and light up a led on pin 5, and to get the state of a button for a led on pin 3.
 * 
 * Needed Component : 
 * - 2 * led
 * - 2 * 220R
 * - Ethernet Shield
 * 
 * Circuit : 
 * 
 * pin 3-------|>----{220R}---GND
 * pin 5-------|>----{220R}---GND
 * 
 */
 #include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char server[] = "www.etienne-desrousseaux.com";//the server where is the system for now

IPAddress ip(192, 168, 0, 177);

EthernetClient client;

char answer[20];

void setup() {
  Serial.begin(9600);//debugging serial
  Serial.println("serial begun");
  
  if (Ethernet.begin(mac) == 0) {
    Serial.println("error while connecting");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);

  delay(10500);//leave a while for ethernet to connect, needed in my case to avoid a hell of "not connected" on serial later on
  Serial.println("connected...");
}

void loop()
{
  delay(250);//check value every 250 millis
  actualizeSwitch();//actualize the button, see at page bottom
  actualizeSlider();//actualize the slider, see next function
}

void actualizeSlider() {

  Serial.println("connecting...");
  if (client.connect(server, 80)) //requests the value of the input named 'slider_test' of the 'test' remote
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /e-duino/getRemoteValue.php?remoteId=test&input=slider_test HTTP/1.1");
    client.println("Host: www.etienne-desrousseaux.com");
    client.println("Connection: close");
    client.println();

    while(!client.available())//wait to get a result
    {
      delay(3);
    }
  }
  else//unable to connect
  {
    Serial.println("not connected");
    if(client.connected())
    {
      Serial.println("still connected");
    }
  }

  //we received the content
  Serial.println("reading content...");
  char endOfHeaders[] = "\r\n\r\n";

  client.setTimeout(10000);
  bool ok = client.find(endOfHeaders);//trying to skip the header
  if(ok)//managed to skip the header
  {
    Serial.println("found content");
    for(int i = 0; i < 3; i++)//for some reasons, there is 3 unwanted characters before the actual content, so we can just skip them
    {
      if(client.available())
      {
        client.read();
      }
    }
    byte b = 0;//how much should we light the led?
    for(byte i = 0; i < 3 && client.available(); i++)//maximum 3 digits (byte can only be between 0 and 255)
    {
      char c = client.read();
      Serial.print(c);
      if(isDigit(c))//it is a digit, we add him to b
      {
        byte b2 = byte(c) - 48;//the char number for 0 is 48, for 1 is 49, and so on until 9, which is then 57
        Serial.print(" - it is a digit - ");
        Serial.println(b2);
        b *= 10;//shift left the actual byte, eg: we receive 21 by client : first char : b = 0, b *= 10, b = 0, b += 2, b = 2; second char : b = 2, b *= 10, b = 20, b += 1, b = 21
        b += b2;
        Serial.println(b);
      }
      else
      {
        i = 10;
      }
    }
    analogWrite(5, b);
  }
  else//the data is not in html format
  {
    Serial.println("bad format data received");
  }
  
  client.stop();
}

void actualizeSwitch() {

  Serial.println("connecting...");
  if (client.connect(server, 80)) //requests the value of the input named 'switch_test' of the 'test' remote
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /e-duino/getRemoteValue.php?remoteId=test&input=switch_test HTTP/1.1");
    client.println("Host: www.etienne-desrousseaux.com");
    client.println("Connection: close");
    client.println();

    while(!client.available())
    {
      delay(3);
    }
  }
  else
  {
    Serial.println("not connected");
    if(client.connected())
    {
      Serial.println("still connected");
    }
  }

  Serial.println("reading content...");
  char endOfHeaders[] = "\r\n\r\n";

  client.setTimeout(10000);
  bool ok = client.find(endOfHeaders);//skip html data
  if(ok)
  {
    Serial.println("found content");
    for(int i = 0; i < 3; i++)//skip unwanted characters
    {
      if(client.available())
      {
        client.read();
      }
    }
    byte b = 0;
    char goal[] = "true";
    while(client.available())//this system can be used for short strings too, since it test characters one by one.
    {
      char c = client.read();
      Serial.println(c);
      if(c == goal[b])
      {
        b++;
        if(b >= 4)//if 4 good characters, then the value starts with 'true', so we're good
        {
          break;
        }
      }
      else//wrong character, we return to 0 and stop there
      {
        b = 0;
        break;
      }
    }
    if(b > 0)
    {
      digitalWrite(3, HIGH);
    }
    else
    {
      digitalWrite(3, LOW);
    }
  }
  else//bad html signature
  {
    Serial.println("bad format data received");
  }
  
  client.stop();
}

If you have any ideas that could improve the project, feel free to comment them :)

Discussions