Pages: [1]   Go Down
Author Topic: Arduino Telnet Server  (Read 3215 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Folks:

There's been some recent interest in the Telnet server sketch I created a couple years back.  The Telnet server allows all Arduino control pins to be read or written using a simple command line protocol.  Once you've loaded the sketch, you should be able to Telnet into the Arduino's IP address, get a prompt, and type ? <cr> for help. 

The code on the old forum was developed in Arduino environment 0.23 and no longer compiles without edits.  I'm posting the updated code here:  http://dl.dropbox.com/u/47320696/ArduinoTelnetServer.zip.

I hope this helps; drop me a note if you find it useful.

Best Regards,

stlentz [at] gmail [dot] com
« Last Edit: March 09, 2012, 12:48:22 pm by SteveTL » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Definetely usefull, it allows one to monitor and manage things over the internet. Web is good for human computer interaction but telnet can also do computer computer very easy.

Thanks for upgrading.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Italy - BO
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi! I was just writing an email to you!
First of all thank you for sharing your work, it's an excellent base to start my project since I do not know very much of programming.

I am adding code to the telnet server for the support of the DHT11/22/21 humidity/temperature sensors.

Is there anyone who is using this code and has expanded it in any way?

Matteo
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
this code
what you mean by this - DHT or Telnet?

DHT - http://playground.arduino.cc/Main/DHTLib -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Italy - BO
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what you mean by this - DHT or Telnet?

DHT - http://playground.arduino.cc/Main/DHTLib -

I meant the Telnet Server code!
Logged

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the update
Logged

Italy - BO
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Premise: I'm an improvised coder.
I have added two parts to the server, one for the temperature readings (but I hadn't time to test it) and one for the reading/writing of 6 variables:

Temperature:
library and settings:
Code:
#include <DHT.h>

//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define DHTPIN 2     // what pin we're connected to
DHT dht(DHTPIN, DHTTYPE);

in the void setup:
Code:
dht.begin();

in the void parseReceivedText added:
Code:
case 'e' : envCommand(); break;

and the rest of the code:
Code:
void envCommand()
// if we got here, textBuff[0] = 'e'
{
switch (textBuff[1]) {
case 't' : envTempCommand(); break;
case 'h' : envHumCommand(); break;
default: printErrorMessage(); break;
}
}

void envTempCommand()
// if we got here, textBuff[0] = 'e' and textBuff[1] = 't'
{
//float h = dht.readHumidity();
  float t = dht.readTemperature();
//  if (isnan(t)) {
    if (isnan(t) && (t) == 0.00) {
   client.println("ERROR reading the sensor ");
        client.print("DEBUG content of t ");
        client.print(t);
        client.println(" "); }
else {
client.print("Temp: ");
client.print(t);
client.print(" *C");
        client.println(" "); }
}

void envHumCommand()
// if we got here, textBuff[0] = 'e' and textBuff[1] = 'h'
{
float h = dht.readHumidity();
  if (isnan(h)) {
client.println("ERROR reading the sensor ");
        client.print("DEBUG content of h ");
        client.print(h);
        client.println(" "); }
else {
client.print("Hum: ");
client.print(h);
client.print(" %\t");
        client.println(" "); }
}


the variables part:
define the variables:
Code:
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;

in the void parseReceivedText added:
Code:
case 'v' : varCommand(); break;


and the variables code:
Code:
void varCommand()
// if we got here, textBuff[0] = 'v'
{
switch (textBuff[1]) {
case 's' : varSetCommand(); break;
case 'r' : varReadCommand(); break;
default: printErrorMessage(); break;
}
}


void varSetCommand()
// if we got here, textBuff[0] = 'v' and textBuff[1] = 's'
{  
if (textBuff[3] == '=') {
  int variable = 0;                       // varible to store my command variable
  variable = parseDigit(textBuff[4]);     // reads the fourth char of my command
     if (variable >= 0 && variable <= 9) {   // check if a number have been entered, isnan didn't quite work
       switch (textBuff[2]) {
         case 'a':
           a = variable;
           client.print("'a' is: ");
           client.println(a);
           client.println("OK! ");
           break;
         case 'b':
           b = variable;
           client.print("'b' is: ");
           client.println(b);
           client.println("OK! ");
           break;
         case 'c':
           c = variable;
           client.print("'c' is: ");
           client.println(c);
           client.println("OK! ");
           break;
         case 'd':
           d = variable;
           client.print("'d' is: ");
           client.println(d);
           client.println("OK! ");
           break;  
         case 'e':
           e = variable;
           client.print("'e' is: ");
           client.println(e);
           client.println("OK! ");
           break;
         case 'f':
           f = variable;
           client.print("'f' is: ");
           client.println(f);
           client.println("OK! ");
           break;    
         default:
           client.println("ERROR: wrong variable ");
       }
     }
   else client.println("ERROR: unfortunately we can only process one digit numbers"); }
else client.println("ERROR: wrong command ");  }


void varReadCommand()
// if we got here, textBuff[0] = 'v' and textBuff[1] = 'r'
{
    switch (textBuff[2]) {
      case 'a':
        client.println(a);
        break;
      case 'b':
        client.println(b);
        break;
      case 'c':
        client.println(c);
        break;
      case 'd':
        client.println(d);
        break;
      case 'e':
        client.println(e);
        break;
      case 'f':
        client.println(f);
        break;
      default:
        client.println("ERROR: wrong variable ");
      }
}

obviously I added the needed text to the help ( void printHelpMessage ):
Code:
client.println(" et -environmental TEMP read: returns the state of the temp sensor");
client.println(" eh -environmental HUMidity read: returns the state of the humidity sensor");
client.println(" vr -variable read: reads a variable");
client.println(" vs -variable set: sets a variable");
client.println(" allowed variables are: a b c d e f ");
client.println(" allowed variables values are numbers between 0-9 ");
« Last Edit: January 18, 2013, 06:17:06 am by gandalfk7 » Logged

Italy - BO
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tested with a DHT22, the temp/hum part seems to work without problems
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thankyou!
Logged

Pages: [1]   Go Up
Jump to: