Go Down

Topic: Arduino Telnet Server (Read 3 times) previous topic - next topic

SteveTL

Mar 06, 2012, 02:14 pm Last Edit: Mar 09, 2012, 06:48 pm by SteveTL Reason: 1
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

robtillaart


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.

Rob Tillaart

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

gandalfk7

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

robtillaart

Quote
this code

what you mean by this - DHT or Telnet?

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

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

gandalfk7


what you mean by this - DHT or Telnet?

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


I meant the Telnet Server code!

Frisky


gandalfk7

#6
Jan 18, 2013, 12:14 pm Last Edit: Jan 18, 2013, 12:17 pm by gandalfk7 Reason: 1
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: [Select]

#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: [Select]
dht.begin();

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

and the rest of the code:
Code: [Select]
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: [Select]
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;


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


and the variables code:
Code: [Select]
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: [Select]
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 ");

gandalfk7

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

Elijahg


Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview