Guten Morgen zusammen,
Nachdem ich jetzt sehr lange einen Bogen um das Thema WIFI gemacht habe, muss es jetzt einfach sein. Und wie zu erwarten, wirklich kein einfaches Thema. Ich hoffe Ihr könnt mir ein wenig helfen.
Wie ist der Stand:
-
Ich habe ein kleine Modellboot, mit dem Mega, CC3000 Wifi Shield von Adafruit, ein paar Servos, ner IMU und GPS. (Also somit der Empfänger)
-
Auf der anderen Seite nen Uno, ebenfalls einen CC3000, sowie einen Joystick, von dem im Moment erstmal nur 2 Achsen analog eingelesen werden. Also 2 Int Werte. (Sender)
Was passiert „an Bord“? Die IMU+GPS+ Servos (welche 4 Flügel unter Wasser am Rumpf ansteuern) steuern über einen internen Algorithmus die Lage des Bootes abhängig von der der Geschwindigkeit und Lenkeinschlag. (Der Loop muss also immer laufen)
Bisher habe ich den Joystick zu testzwecken direkt am Boot an gestöpselt. Es funktioniert auch alles besten.
Nun ist das mit dem Kabel aber keine Lösung und somit muss eine Drahtlose Übertragung her.
Und da habe ich mich jetzt die letzten Tage beschäftig und stelle fest, dass mir zum einen einfach die Kenntnisse etwas fehlen, zum anderen, wieder mal mein Englisch mir im Wege steht… Vor allem diese beiden Shields von Adafruit…
Was habe ich bisher:
- Beide Shields konnte ich mit einer festen IP (192.168.1.2 sowie 3) an einem AP anmelden.
- Ich habe das Beispiel ECHOServer laufen lassen und konnte von meinem PC aus über einen TCP Packet Sender zeichen an den Server senden. (Code anbei)
- Ich habe auf der anderen Seite eine Client aufmachen können (Code anbei), der sich mit dem Server verbindet. Leider sendet er meine Zeichen nicht. Und hier check ich noch nicht, wie das aussehen muss.
Diesen Teil führe ich hier nochmal explizit auf.
ECHO SERVER:
/***************************************************
Adafruit CC3000 Breakout/Shield TCP Echo Server
This is a simple implementation of the echo
protocol, RFC 862 http://tools.ietf.org/html/rfc862 ,
for the Arduino platform and Adafruit CC3000 breakout
or shield. This sketch will create a TCP server that
listens by default on port 7 and echos back any data
received. Up to 3 clients can be connected concurrently
to the server. This sketch is meant as an example of how
to write a simple server with the Arduino and CC3000.
See the CC3000 tutorial on Adafruit's learning system
for more information on setting up and using the
CC3000:
http://learn.adafruit.com/adafruit-cc3000-wifi
Requirements:
****************************************************/
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 2 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 3
#define ADAFRUIT_CC3000_CS 4
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "Sky-Net" // cannot be longer than 32 characters!
#define WLAN_PASS "myPassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define LISTEN_PORT 7 // What TCP port to listen on for connections. The echo protocol uses port 7.
Adafruit_CC3000_Server echoServer(LISTEN_PORT);
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
// Start listening for connections
echoServer.begin();
Serial.println(F("Listening for connections..."));
}
void loop(void)
{
// Try to get a client which is connected.
Adafruit_CC3000_ClientRef client = echoServer.available();
if (client) {
// Check if there is data available to read.
if (client.available() > 0) {
// Read a byte and write it to all clients.
uint8_t ch = client.read();
client.write(ch);
}
}
}
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}