Go Down

Topic: Wireless LAN (WLAN) Shield in Verbindung mit iOS (iPhone, iPad, iPod touch, etc) (Read 3 times) previous topic - next topic

gloob

Also ich habe das RedFly erfolgreich mit Airport Extreme in Betrieb und als Ad-Hoc Modus mit einem iPod oder iPad.

Ich kann heute Abend gerne Sample Code bereitstellen wenn bedarf besteht.

berlin86

Hallo,

ja den Code bitte immer im Forum teilen, wenn ich mein Projekt: RFID Lesegerät mit Türöffner aus Arduino Uno, RedFly und LCDKeypad Shield fertig habe mach ich das auch.

Wenn du im Ad-Hoc Modus bist kannst du doch direkt auf dein iPod rauf oder, mit Airport Extrem bist du doch im Infrastruktur Modus?

Danke
From Berlin, Germany

vega

Hallo

ich habe mittlerweile auch das RedFly Shield hier.
Es funktioniert soweit alles prima. Pins anlöten und mit den Sample Sketches kann man mit ein wenig knowhow schon simple erste Szenarien umsetzen.
Der Betrieb im Ad-hoc Modus ist einwandfrei!
Hat jemand schon weitere Erfahrung gemacht was zb html Formulare betrifft? Ist es umsetzbar zb Eingabefelder zu erstellen deren Eingaben dann in Variablen eingesetzt werden können mit denen der Arduino dann arbeiten kann?

Oder gibt es noch eine weitere Möglichkeit, außer über html, Daten zwischen dem RedFly und einem mit wlan angebundenem Gerät auszutauschen?

Grüße
Vega

gloob

So hier mal ein stückchen Code von mir um eine Teleskopmontierung mit dem Arduino und Redfly shield zu steuern.
Benutzen tue ich dafür im Moment HTML Formulare.

Code: [Select]
/*
  Web Server

This sketch acts as a server
using an Arduino RedFly-Shield.
*/

#include <RedFly.h>
#include <WProgram.h>
#include <soft_merlin_mount.h>

#define LED_Merlin_Connected 12
#define LED_Merlin_Move      13
#define LED_WLAN_Connected   11

byte ip[]      = {
  192,168,001,230}; //ip from shield (server)
//byte ip[]      = {192,168,1,101};
byte netmask[] = {
  255,255,255,0  }; //netmask

uint8_t   http=0xFF;   //socket handle
uint16_t  http_len=0; //receive len
char http_buf[64];   //receive buffer
char substring[32];

byte LED_on = 0;
byte TimerCounter = 0;

long pos_pitch = 0;
long pos_yaw = 0;

long startpoint_pitch = 0;
long startpoint_yaw = 0;
long endpoint_pitch = 0;
long endpoint_yaw = 0;

String readString = "";

uint8_t sock = 0, buf[32];

char* Button_Start  = "<form method=get><input type=submit name=MERLIN value=";
char* Ende   = "></form>";
char* Textbox_Start = "<form method=get><input type=text name=value size=25><input type=submit name=MERLIN value=";

void debugout(char *s)  {
  RedFly.disable();
  Serial.print(s);
  RedFly.enable();
}
void debugoutln(char *s){
  RedFly.disable();
  Serial.println(s);
  RedFly.enable();
}



void setup()
{
  uint8_t ret;

  pinMode(LED_Merlin_Connected, OUTPUT);
  pinMode(LED_Merlin_Move, OUTPUT);
  pinMode(LED_WLAN_Connected, OUTPUT);

  // Connect Merlin
  Merlin_Connect();
 
  //init the WiFi module on the shield
  //ret = RedFly.init(HIGH_POWER); //LOW_POWER MED_POWER HIGH_POWER
  ret = RedFly.init(115200, HIGH_POWER);
  if(ret)
  {
    //debugoutln("INIT ERR");
  }
  else
  {
    //scan for wireless networks (must be run before join command)
    RedFly.scan();

    //join network
    ret = RedFly.join("ABC", "***", INFRASTRUCTURE);
    if(ret)
    {
      //debugoutln("JOIN ERR");
    }
    else
    {
      ret = RedFly.begin(ip, 0, netmask);
      if(ret)
      {
        //debugoutln("BEGIN ERR");
        RedFly.disconnect();
      }
      else
      {
        http = RedFly.socketListen(PROTO_TCP, 80); //start listening on port 80
        if(http == 0xFF)
        {
          //debugoutln("SOCKET ERR");
          RedFly.disconnect();
        }
        else
        {
          //WLAN connected
          //debugoutln("connected");
          digitalWrite(LED_WLAN_Connected, HIGH);
        }
      }
    }
  }

  delay(500);
 
  digitalWrite(LED_WLAN_Connected, LOW);
  delay(500);
  digitalWrite(LED_WLAN_Connected, HIGH);
}


void loop()
{
  Webserver();
}


void Merlin_Connect()
{
  merlin.init();

  pos_pitch = merlin.readAxisPosition(AXIS_PITCH);
  pos_yaw = merlin.readAxisPosition(AXIS_YAW);

  if(pos_pitch > 0 && pos_yaw > 0) digitalWrite(LED_Merlin_Connected, HIGH);
}

void Merlin_Move(long degree, int move_direction)
{
  if(move_direction==0)
  {
    pos_yaw = pos_yaw + merlin.fromAngle(degree);
  }
  else
  {
    pos_pitch = pos_pitch + merlin.fromAngle(degree);
  }

  Merlin_Goto(pos_pitch, pos_yaw);
}

void Merlin_Goto(long pitch, long yaw)
{
  digitalWrite(LED_Merlin_Move, HIGH);
  merlin.driveToPositionBothAxis(yaw, pitch, SYNC_SYNCHRONY);
  digitalWrite(LED_Merlin_Move, LOW);

  pos_pitch = pitch;
  pos_yaw = yaw;
}

unsigned long ParseValueFromString(String string)
{
  unsigned long value = 0;
  int index = string.indexOf("value=");

  if(index >= 0)
  {
    for(int i = 0; i < 3; i++)
    {
      substring[i] = http_buf[index + 6 + i];
    }

    value = atol(substring);

    return value;
  }
  else
  {
    return 0;
  }
}


void Webserver()
{
  uint16_t rd, len;

  if(http == 0xFF) //no socket open
  {
    return;
  }

  sock = 0xff; //return data from all open sockets
  rd = RedFly.socketRead(&sock, &len, 0, 0, buf, sizeof(buf));

  if(sock == http)
  {
    if((rd != 0) && (rd != 0xffff))
    {
      if((http_len+rd) > sizeof(http_buf))
      {
        rd = sizeof(http_buf)-http_len;
      }
      memcpy(&http_buf[http_len], buf, rd);
      http_len += rd;
    }

    if((rd == 0xffff)  || (len == 0)) //connection closed or all data received
    {
      //debug request message from iPod
      //debugoutln("Request: ");
      //debugoutln(http_buf);

      readString = http_buf;

      if(readString.indexOf("GET / HTTP") >= 0)
      {
      }
      else if(readString.indexOf("UP") >= 0)
      {
        Merlin_Move(ParseValueFromString(readString),1);
      }
      else if(readString.indexOf("DOWN") >=0)
      {
        Merlin_Move(-1 * ParseValueFromString(readString),1);
      }
      else if(readString.indexOf("LEFT") >=0)
      {
        Merlin_Move(-1 * ParseValueFromString(readString),0);
      }
      else if(readString.indexOf("RIGHT") >=0)
      {
        Merlin_Move(ParseValueFromString(readString),0);
      }
      else if(readString.indexOf("Set_Start") >=0)
      {
        startpoint_yaw = pos_yaw;
        startpoint_pitch = pos_pitch;
      }
      else if(readString.indexOf("Set_End") >=0)
      {
        endpoint_yaw = pos_yaw;
        endpoint_pitch = pos_pitch;
      }
      else if(readString.indexOf("Goto_Start") >=0)
      {
        Merlin_Goto(startpoint_pitch, startpoint_yaw);
      }
      else if(readString.indexOf("Goto_End") >=0)
      {
        Merlin_Goto(endpoint_pitch, endpoint_yaw);
      }
      else
      {
      }

      Send_Main();

      //reset input buffer
      http_buf[0] = 0;
      http_len    = 0;
      readString = "";

      //close connection
      RedFly.socketClose(sock);

      //restart listening
      http = RedFly.socketListen(PROTO_TCP, 80);
    }
  }
}

void Send_Main()
{
  //HTML header
  RedFly.socketSend(sock, PSTR("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"), 46); //Content-Length: xx\r\n

  // Write Merlin position
  sprintf((char*)buf, "<br /> yaw: %lu ", pos_yaw);
  RedFly.socketSend(sock, (char*)buf);
  sprintf((char*)buf, "<br /> pitch: %lu ", pos_pitch);
  RedFly.socketSend(sock, (char*)buf);
  sprintf((char*)buf, "<br /> start_yaw: %lu ", startpoint_yaw);
  RedFly.socketSend(sock, (char*)buf);
  sprintf((char*)buf, "<br /> start_pitch: %lu ", startpoint_pitch);
  RedFly.socketSend(sock, (char*)buf);
  sprintf((char*)buf, "<br /> end_yaw: %lu ", endpoint_yaw);
  RedFly.socketSend(sock, (char*)buf);
  sprintf((char*)buf, "<br /> end_pitch: %lu ", endpoint_pitch);
  RedFly.socketSend(sock, (char*)buf);

  RedFly.socketSend(sock, "<br />");

  Send_Textbox("DOWN");
  Send_Textbox("UP");
  Send_Textbox("RIGHT");
  Send_Textbox("LEFT");

  Send_Button("Set_Start");
  Send_Button("Set_End");
  Send_Button("Goto_Start");
  Send_Button("Goto_End");
}

void Send_Textbox(char* Buttonname)
{
  RedFly.socketSend(sock, Textbox_Start);
  RedFly.socketSend(sock, Buttonname);
  RedFly.socketSend(sock, Ende);
}

void Send_Button(char* Buttonname)
{
  RedFly.socketSend(sock, Button_Start);
  RedFly.socketSend(sock, Buttonname);
  RedFly.socketSend(sock, Ende);
}






vega

hey gloob

cool, vielen Dank für dein Beitrag. Ich werde mir das in kürze mal ansehen!

Go Up