Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Eth.shield: Change host url and ip at runtime on: May 04, 2011, 12:40:19 am
Ok, meanwhile i managed to make my sketch prompt me for hostname, but ip is still hardcoded. Here i need a promt for ip adress and then convert this string to an array of bytes which is the ip adress of the host. (maybe one of you is able  to code this).

See my sketch afterwards.

Also i peeked into the example of the DNS library but found, that it is beyond my skills smiley-wink

Code:
/*

serial to web interface.
an string received at the serial interface will be sent
to an server with hardcoded domain name and ip.

the string at the serial interface should look like:
GET /index.php?0=A&1=B  HTTP/1.1
if index.php is in root directory

to do: add DHCP and DNS

*/

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };     // your desired mac address!
byte ip[] = { 192,168,178,5 };                            // the ip address of your arduino in you intranet!
byte gateway[] = { 192, 168, 178, 1 };                    // the gateway address of your dsl router!
byte subnet[]  = { 255, 255, 255, 0 };                    // corresponding subnet mask
byte server[] = { aaa,bbb,ccc,ddd };                         // ip of remote host
Client client(server, 80);
char c;
String host;
String readString;
boolean eot = false;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("# Arduino web client");
  Serial.println("# Remote server IP: aaa,bbb,ccc,ddd");
  Serial.println("# Remote host adress: www.yourdomain.org");
//  Ethernet.begin(mac, ip, gateway, subnet); 
//  delay(5000);                   // wait, until LAN shield ist up
// here was it before
}

void loop()
{
 
  //arduino reads host URL
  Serial.println("# input for example 'www.yourdomain.org'"); 
  Serial.println("# >");
  host="";
 
  eot = false;
  while (eot == false) {
      while (Serial.available()) {
        char c = Serial.read();  //gets one byte from serial buffer
        Serial.print(c);
        if (c == 0x0d){
          eot = true;
          break;
        }
        host += c;
      } 
  }
  Serial.println();   
 
 
 
 
  //arduino reads string to be transmitted to remote host
  Serial.println("# input for example 'GET /index.php?0=255&1=30  HTTP/1.1'"); 
  Serial.println("# >");
  readString="";
 
  eot = false;
  while (eot == false) {
      while (Serial.available()) {
        char c = Serial.read();  //gets one byte from serial buffer
        Serial.print(c);
        if (c == 0x0d){
          eot = true;
          break;
        }
        readString += c;
      } 
  }
  Serial.println();   

  //host[] = "www.infragelb.de";
  byte server[] = { aaa,bbb,ccc,ddd };
  Ethernet.begin(mac, ip, gateway, subnet); 
  delay(5000);                   // wait, until LAN shield ist up


  //arduino transmits data to remote host
  if (client.connect())  // make connection to host
  {
    Serial.println("# connected...uploading...");
    client.println(readString);
    client.print("Host: ");
    client.println(host);
    client.println();
    Serial.println("# done");
  }
  else
  {
    Serial.println("# no connection");
  }
  delay(900);


  // arduino reading answer from remoto host and sends it out on serial interface
  Serial.println();
  Serial.println("# remote server says:");
  while (client.connected()){
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }   
  }
  //answer of remote host finished
  client.stop(); 
  client.flush(); 
  delay(1000);
  Serial.println();
  Serial.println("# disconnecting."); 
}


   
2  Using Arduino / Networking, Protocols, and Devices / Re: Eth.shield: Change host url and ip at runtime on: May 02, 2011, 03:39:16 pm
Hello Painkillaz

i phoned my hosting provider and was told that HOST string. Already i've worked out a couple of php scripts (drafts) and i think i can live with this solution. Arduino is calling his php script, passing his parameters and receiving data in return. This data is kept in a settings.txt file, wich is edited with a simple php form script.

In practical use i fill in some lines of at commands, for example "at led1 on, at heater 25", press "submit" and open index.html to see the results. index.html is a file written by the php script wich is called by the arduino, the content of the html file depends on the parameters passed.

For maximum comfort i connect arduino to other uC via bluetooth. In other words: All my controllers sitting around can log in via BT to the arduino, submit their data and receive commands.

The various controllers run a litte parser program to interprete my "at" command lines.

You can see  schematic here on our flipdot hackerspace kassel page, later on i will also provide the description in english.

Hack on
snafu
3  Using Arduino / Networking, Protocols, and Devices / Re: Eth.shield: Change host url and ip at runtime on: May 01, 2011, 11:27:37 pm
Hm, thanks!

Yes, i only have one connect-transfer-disconnect session a time, then stop the client. So it should work, you say...
Thought i tried this and struggled with these objects thingy smiley-wink Will try this again, hoping for success.

Thanks for your answer.
4  Using Arduino / Networking, Protocols, and Devices / Eth.shield: Change host url and ip at runtime on: May 01, 2011, 02:48:47 pm
Hi all,

im pretty happy with my small sketch providing a serial to web client, allowing to pass an GET request to an remote host.

But:
I failed in any attempt to change the host url and ip at runtime. It would be perfect if i could transmit via serial hostname, then ip and at last the GET request.
Would you pleas be so kind and examine my code snippet provided?

Thank you in advance!
Snafu

Code:
/*

serial to web interface.
an string received at the serial interface will be sent
to an server with hardcoded domain name and ip.

the string at the serial interface should look like:
GET /index.php?0=A&1=B  HTTP/1.1
if index.php is in root directory

to do: add DHCP and DNS

*/

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };     // your desired mac address!
byte ip[] = { 192,168,178,5 };                            // the ip address of your arduino in you intranet!
byte gateway[] = { 192, 168, 178, 1 };                    // the gateway address of your dsl router!
byte subnet[]  = { 255, 255, 255, 0 };                    // corresponding subnet mask
byte server[] = { aaa,bbb,ccc,ddd };                         // ip of remote host
Client client(server, 80);
char host[] = "www.yourcooldomain.org";                   // domain name of remote host, neccessary cause of shared hosting
char c;
String readString;
boolean eot = false;

void setup()
{
  Serial.begin(9600);
  Serial.println();
  Serial.println("# Arduino web client");
  Serial.println("# Remote server IP: aaa,bbb,ccc,ddd");
  Serial.println("# Remote host adress: www.yourcooldomain.org");
  Ethernet.begin(mac, ip, gateway, subnet); 
  delay(5000);                   // wait, until LAN shield ist up
}

void loop()
{
  //arduino reads string to be transmitted to remote host
  Serial.println("# input for example 'GET /index.php?0=255&1=30  HTTP/1.1'"); 
  Serial.println("# >");
  readString="";
 
  eot = false;
  while (eot == false) {
      while (Serial.available()) {
        char c = Serial.read();  //gets one byte from serial buffer
        Serial.print(c);
        if (c == 0x0d){
          eot = true;
          break;
        }
        readString += c;
      } 
  }
  Serial.println();   


  //arduino transmits data to remote host
  if (client.connect())  // make connection to host
  {
    Serial.println("# connected...uploading...");
    client.println(readString);
    client.print("Host: ");
    client.println(host);
    client.println();
    Serial.println("# done");
  }
  else
  {
    Serial.println("# no connection");
  }
  delay(900);


  // arduino reading answer from remoto host and sends it out on serial interface
  Serial.println();
  Serial.println("# remote server says:");
  while (client.connected()){
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }   
  }
  //answer of remote host finished
  client.stop(); 
  client.flush(); 
  delay(1000);
  Serial.println();
  Serial.println("# disconnecting."); 
}


   
5  Forum 2005-2010 (read only) / Interfacing / Re: Twittering using ethernet shield (Basics) on: February 09, 2009, 02:23:09 am
Ah, here is another solution for twittering with Arduino, not jet tested by me.
6  Forum 2005-2010 (read only) / Interfacing / Twittering using ethernet shield (Basics) on: February 07, 2009, 12:36:40 pm
Hello,

just managed to get my arduino posting the first tweet. Lacking programming skills this is only a rude skeleton of a final program smiley

Nevertheless, here is the code, maybe it helps someone (i found nearly nothing according to twitter in this forum) have fun!



Code:
// a brute test of twittering with arduino.
// source for handling the twitter api was http://pratham.name/post/39551949/twitter-php-script-without-curl
// the scetch lacks a lot of functionality, the encoding of username and password must be done separately
// and the message is fixed (text is "Yahoo, im twittering!")
//
// this is due to my ony basic knowledge
// maybe someone can use this snippet and have fun with it


#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 10 };                      // this is the ip within my lan
byte gateway[] = { 192, 168, 2, 1 };                  // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 128, 121, 146, 100 };               // Twitter's ip

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.begin(9600);
  
  delay(1000);
  Serial.println("connecting...");
  
  if (client.connect()) {
    Serial.println("connected");
    client.println("POST http://twitter.com/statuses/update.json HTTP/1.1");
    client.println("Host: twitter.com");
    client.println("Authorization: Basic #################");    // the string of ###s after "Basic" is the base64_encoded Text of username:password of your twitter account
                                                                        // you can do the encoding at this site: http://www.functions-online.com/en/base64_encode.html
    client.println("Content-type: application/x-www-form-urlencoded");
    client.println("Content-length: 28");                               // this is the length of the text "Yahoo, im twittering!"
    client.println("Connection: Close");
    client.println();
    client.print("status=Yahoo, im twittering!");

  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}
7  Forum 2005-2010 (read only) / Deutsch / Re: Processing != C != Wiring != Java on: January 31, 2009, 11:19:44 am
Thanks for answering. Thinking about using the Arduino in education, the language matters.
8  Forum 2005-2010 (read only) / Deutsch / Processing != C != Wiring != Java on: January 30, 2009, 10:09:47 am
Hallo zusammen!

Aus den Docs zu Arduino bekam ich verwirrende Info, in welcher Sprache denn nun die Boards programmiert werden. Processing, so weit habe ich verstanden, ist eine Sprache für iterative Grafikerzeugung.

Was ich in den Beispielen sehe, ist doch C-Syntax, oder irre ich da? Wäre auch logisch, denn drunter liegt ja gnucc.
Die IDE selbst soll wohl in Java geschrieben sein.

Kann mich jemand von euch mal aufklären?

Danke!
Samuel

9  Forum 2005-2010 (read only) / Interfacing / Ethernet Shield and LCD conflict: Server hangs on: February 06, 2010, 04:57:25 am
Hi all,

wrestling with a strange problem, and would be very happy, if one of you could give me an hint:

Webserver code works pretty fine, separate LCD code works as well, but if i combine both, the webserver hangs.

If i add this line (All other lcd commands are commented out):
Code:
LiquidCrystal lcd(RS, E, D4, D5, D6, D7 );

The server only delivers part of the page, an then seems to stop.
Strangely, on the page only the submit button is missing.

Without LCD initialisation:




With LCD initialisation:



I use the original ethernet shield, Arduino 2009, and an 20x2 LCD.

LCD connected like this:
int RS = 9;
int E = 3;
int D4 = 6;
int D5 = 8;
int D6 = 4;
int D7 = 5;

As far as i found in the internets, there is no pin conflict so far.


My code looks like this:

Code:
// Small Arduino Webserver
// by Andreas Cahen
//
// Used libraries and examples:
//
// Arduino Ethershield, server.pde
// TextString Library, WString.h
// Blinkm Library, BlinkMfuncs.h


#include <Ethernet.h>
#include <WString.h>
#include <LiquidCrystal.h>
//#include <LCD4Bit_mod.h>


#define maxLength 142

int RS = 9;
int E = 3;
int D4 = 6;
int D5 = 8;
int D6 = 4;
int D7 = 5;



byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
  192, 168, 2, 10 };
String inString = String(maxLength);
String Anzeigetext = String(maxLength);
String pin = String(40);
int textstart;
int pinstart;
int intpin;
boolean rightpin;
byte cols = 20;
byte rows = 2;

Server server(80);

//int ledPin = 2;                 // LED connected to digital pin 13

void setup()
{
  LiquidCrystal lcd(RS, E, D4, D5, D6, D7 ); // Initializing Liquid Cristal display
  //pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600);
  Serial.println("Starting Server...");
  Ethernet.begin(mac, ip);
  server.begin();

//  lcd.begin(cols, rows);
//  lcd.print("Hallo Welt");
//  delay (1000);
//  lcd.begin(cols, rows);  
}


void loop()
{
  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (inString.length() < maxLength) {
          inString.append(c);
        }        
        if (c == '\n' && current_line_is_blank) {
          if (inString.contains("?")) {
            //Serial.println(inString); //show al received characters up to max string length

            //find position of form field name QTXT in string
            int textstart = inString.indexOf("QTXT");

            //find position of form field name QPIN in string    
            int pinstart = inString.indexOf("QPIN");

            //extract the text to be displayed on lcd out of the instring
            Anzeigetext = inString.substring(textstart+5, pinstart-1);  

            //replace the annoing "+" chracters in instring with " " as originally typed in form field
            Anzeigetext.replace( '+', ' ');

            //extract the pin number string out of the instring
            pin = inString.substring(pinstart+5, pinstart+9);

            //calculate numerical value of pin and test if it matches the right number
            intpin = atoi(pin);
            if (intpin == 1684)
            {
              rightpin = true;
              //digitalWrite(ledPin, HIGH);   // sets the LED on
              Serial.println(Anzeigetext);
              //lcd.print(Anzeigetext);
            }
            else
            {
              rightpin = false;
              Serial.println("Falsche Pin");
              //digitalWrite(ledPin, LOW);   // sets the LED off

            }

          }

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><head></head><body>");
          client.println("<h1>Input text to display</h1>");
          client.println("<form method=get>Text:<input type=text size=140 name=QTXT></br></br></br>Pin:<input type=text size=4 name=QPIN></br></br></br><input type=submit value=submit></form>");      

          if (rightpin)
          {
            client.println(Anzeigetext);        
          }
          else
          {
            client.println("Falsche PIN");                
          }

          client.println("</body></html>");          
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          current_line_is_blank = false;
        }
      }
    }
    delay(1);
    inString = "";
    client.stop();
  }
}

Pages: [1]