Show Posts
Pages: 1 ... 3 4 [5]
61  International / Deutsch / Re: Verarbeitung von Posts on: May 17, 2012, 07:20:04 am
Jippy! Habe es geschafft smiley
Der Code mag zwar nicht ganz sauber sein, aber er funktioniert super!

der attribute "action" hat nun 4 Parameter. open, close, stop und status.

Lösung sieht wie folgt aus:

Code:
#define WEBDUINO_AUTH_REALM "Access Logs"

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


static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 0, 198 };

#define WEBDUINO_FAIL_MESSAGE "<h1>404</h1>"
#define PREFIX "/garage"
#define OPEN_PIN 5
#define CLOSE_PIN 3
#define STOP_PIN 6
#define DOOR_CONTACT 7
#define NAMELEN 32
#define VALUELEN 32

int doorState = 0; 
char open = LOW;           
char close = LOW;           
char stop = LOW; 
String outputmsg;
int cnt=0;
WebServer webserver(PREFIX, 80);

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (server.checkCredentials("dXNlcjp1c2Vy"))
  {
    URLPARAM_RESULT rc;
  char name[NAMELEN];
  int  name_len;
  char value[VALUELEN];
  int value_len;

  server.httpSuccess(); //alles ok header

  /* if we're handling a GET or POST, we can output our data here.
     For a HEAD request, we just stop after outputting headers. */
  if (type == WebServer::HEAD)
    return;
   
  if (strlen(url_tail))
    {
    while (strlen(url_tail))
      {
        rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN);
        if (rc != URLPARAM_EOS)
        {
         
          if (strcmp(name, "action") == 0) //wenn action= ...
          {
            if (strcmp(value, "open") == 0)
            {
              server.print("Tor wird ge&ouml;ffnet");
              stop=LOW;
              close=LOW;
              open=HIGH;
            }
            if (strcmp(value, "close") == 0)
            {
              server.print("Tor wird geschlossen");
              stop=LOW;
              close=HIGH;
              open=LOW; 
          }
            if (strcmp(value, "stop") == 0)
            {
              server.print("Tor wird angehalten");
              stop=HIGH;
              close=LOW;
              open=LOW;
          }
            if (strcmp(value, "status") == 0)
            {
              if (doorState == HIGH)
              {     
                server.print("Tuer geschlossen:<br>");
              }
              else
              {
                server.print("Tuer offen:<br>");
              }     
            }
          }
        }
      }
    }
  }
  else
  {
    /* send a 401 error back causing the web browser to prompt the user for credentials */
    server.httpUnauthorized();
  }
}



void setup()
{
  pinMode(OPEN_PIN, OUTPUT);
  pinMode(CLOSE_PIN, OUTPUT);
  pinMode(STOP_PIN, OUTPUT);
  pinMode(DOOR_CONTACT, INPUT);     
 
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("index.html", &defaultCmd);
  webserver.begin();
}

void loop()
{
  char buff[64];
  int len = 64;
  doorState = digitalRead(DOOR_CONTACT);
  digitalWrite(OPEN_PIN, open);
  digitalWrite(CLOSE_PIN, close);
  digitalWrite(STOP_PIN, stop);   // set the LED on
 
  if(open == HIGH || close == HIGH || stop == HIGH)
  {
    cnt++;
    if(cnt >= 5000)
    {
      open =LOW;
      close=LOW;
      stop=LOW;
      cnt=0;
    }
  }
 
  /* process incoming connections one at a time forever */
  webserver.processConnection(buff, &len);
}
62  International / Deutsch / Re: Verarbeitung von Posts on: May 17, 2012, 01:57:44 am
Stimmt, das war zu Testzwecken. Habe es korrigiert. Aber auch so läuft es leider nicht.
Ich weiß einfach nicht, wie ich diese Wert abfragen kann.
63  International / Deutsch / Verarbeitung von Posts on: May 16, 2012, 05:35:51 pm
Hallo, ich bin ziemlich neu im Arduino gebiet und stehe gerade vor ein paar für mich schwer löslichen Problemen.

Ich möchte später per Webbrowser ein Relais für wenige Sekunden schalten, dafür nutze ich die Webduino Libary.
Als Basis habe ich die Samples von Webduino Authentification mit Web_Ajax_RGB kombiniert.
Mein Problem ist es momentan die Parameter abzufragen und dann die jeweilige Funktion auszuführen.
Dabei verstehe ich den Aufbau von readPOSTparam nicht wirklich.

Ich möchte ein Parameter mit dem Namen "action" senden und dabei 3 verschiedene Values nutzen "open", "close" oder "stop"
Was stimmt an meinem Code nicht, bzw wie kann ich die Werte abfragen?


Code:
#define WEBDUINO_AUTH_REALM "Access Logs"

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


static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 0, 198 };

#define PREFIX "/garage"
#define OPEN_PIN 5
#define CLOSE_PIN 3
#define STOP_PIN 6

int open = 0;            
int close = 0;          
char stop = HIGH;  
String outputmsg;

WebServer webserver(PREFIX, 80);

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  if (server.checkCredentials("dXNlcjp1c2Vy"))
  {
    if (type == WebServer::POST)
    {
      bool repeat;
      char name[16], value[16];
      do
      {
        /* readPOSTparam returns false when there are no more parameters
         * to read from the input.  We pass in buffers for it to store
         * the name and value strings along with the length of those
         * buffers. */
        repeat = server.readPOSTparam(name, 16, value, 16);
  
        /* this is a standard string comparison function.  It returns 0
         * when there's an exact match.  We're looking for a parameter
         * named red/green/blue here. */
        if (strcmp(name, "open") == 0)
        {
    /* use the STRing TO Unsigned Long function to turn the string
     * version of the color strength value into our integer red/green/blue
     * variable */
          open = strtoul(value, NULL, 10);
        }
        if (strcmp(name, "action") == 0)
        {
          close = strtoul(value, NULL, 10);
        }
        if (strcmp(name, "action") == 0)
        {
          stop = HIGH;
          //outputmsg = value;
        }
        else
        {
          stop = LOW;
          //outputmsg = "LOW";
        }
      }
      while (repeat);
      
      // after procesing the POST data, tell the web browser to reload
      // the page using a GET method.
      server.httpSeeOther(PREFIX);
      //    Serial.print(name);
      //    Serial.println(value);

      return;
    }
    server.httpSuccess();
    if (type == WebServer::GET)
    {
      /* store the HTML in program memory using the P macro */
       P(message1) =
      "<!DOCTYPE html><html><head>"
        "<meta charset=\"utf-8\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\" /><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">"
        "<title>Webduino RGB</title>"
      "</head>"
      "<body>"
      "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"/garage\">"
      
    
        "<input type=\"radio\" name=\"action\" id=\"radio\" value=\"open\" />"
        "open<br />"
        "<input type=\"radio\" name=\"action\" id=\"radio2\" value=\"close\" />"
        "close<br />"
        "<input type=\"radio\" name=\"action\" id=\"radio3\" value=\"stop\" />"
        "stop<br />"
      
         "<input type=\"submit\" name=\"button\" id=\"button\" value=\"Senden\" />"
      "</form>";
       P(message2) =
        "</body>"
      "</html>";
    
      //server.printP(message1);
      server.print(close);
      //server.printP(message2);
    }
  }
  else
  {
    /* send a 401 error back causing the web browser to prompt the user for credentials */
    server.httpUnauthorized();
  }
}



void setup()
{
  pinMode(OPEN_PIN, OUTPUT);
  pinMode(CLOSE_PIN, OUTPUT);
  pinMode(STOP_PIN, OUTPUT);
 
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("index.html", &defaultCmd);
  webserver.begin();
}

void loop()
{
  char buff[64];
  int len = 64;
  
  analogWrite(OPEN_PIN, open);
  analogWrite(CLOSE_PIN, close);
  digitalWrite(STOP_PIN, stop);   // set the LED on
 
  /* process incoming connections one at a time forever */
  webserver.processConnection(buff, &len);
}
64  Using Arduino / General Electronics / Re: 230V Input check for Arduino? on: March 25, 2012, 11:53:18 am
i don´t like to check the position by magnetswitchs. I think this is a simple way, but not the best and exact way.
mmoscz version is more helpfull for me, so i can also see in wich direction the garagedoor is moving at the moment.
The Webserver can deliver the actual status of it and the iphone app will show the status smiley

Btw. Its not the problem to switch the garage door. i only need a relay that can switch a 14v power, but its just a single button for move-up/stop/move-down.

@Constantin i thought it would be better to check the 230v outputs of the controller, instead of soldering in the original circuit. smiley

65  Using Arduino / General Electronics / Re: 230V Input check for Arduino? on: March 17, 2012, 10:29:47 am
Thanks for your reply! Dont worry, i have more expirience with Highvoltage than microcontroller.
I would Never connect a 230v supply directly to a arduino. I have a Schooling in electrician, but mircocontrollers and low current is new for me smiley
So i Need to learn more about optocoupler and so on.. Thats why i ask smiley
66  Using Arduino / General Electronics / 230V Input check for Arduino? on: March 17, 2012, 06:06:30 am
Hi Guys,

i like to "hack" an garage door and want to controll the door with a webbrowser.
For this i need to check the actual status of the Door. So i need to check the 230V relais from the Garagedoor controller.

One way is to use another 230v relais, that switch a channel from the arduino, but i think this isn´t the best way.
Any ideas to check with arduino if theres a 230v power present at a input channel?

Pages: 1 ... 3 4 [5]