so, hab jetzt mal etwa 90% des Codes dokumentiert und außerdem den Request auf GET umgestellt - versuch mal ob es so funktioniert - wenn ja, sollte man im Log einen GET-Request erkennen...
#include <RedFly.h>
// IP Einstellungen
byte ip[] = { 192,168, 1,138 }; // IP Adresse des Shields
byte netmask[] = { 255,255,255, 0 }; // Subnetzmaske
byte gateway[] = { 192,168, 1, 1 }; // Gateway IP
byte dnsserver[] = { 192,168, 1, 1 }; // DNS-Server IP
byte serverIP[] = {0,0,0,0}; // früher mal server[] - ich hab spaßhalber mal Nullen eingesetzt, da ich hoffe dass es nach dem Aufruf von getip() überschrieben wird.
#define HOSTNAME "mwsystec.de" // Hostname zu dem verbunden werden soll
uint8_t http=0xFF; //socket handle, HTTP-Fehler
uint16_t http_len=0; //receive len
char http_buf[512]; //Receive-Buffer
//serial format: 9600 Baud, 8N2
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;
ret = RedFly.init(); // Redfly initialisieren
if(ret) // Falls Redfly einen Fehler verursacht, bekommt "ret" einen Rückgabewert
{
debugoutln("INIT ERR"); //there are problems with the communication between the Arduino and the RedFly
}
else
{
//Nach Netzwerken scannen
RedFly.scan();
//dem Netzwerk beitreten
ret = RedFly.join("******", "1*****", INFRASTRUCTURE);
if(ret)
{
debugoutln("JOIN ERR");
for(;;); //do nothing forevermore
}
else
{
// Redfly IP-Konfiguration einstellen, begin(1) benutzt DHCP, andernfalls die jeweilige Konfiguration
ret = RedFly.begin(ip, dnsserver, gateway, netmask);
if(ret) // Eventuellen Fehler abfangen
{
debugoutln("BEGIN ERR");
RedFly.disconnect();
for(;;); //Endlosschleife
}
else
{
if(RedFly.getip(HOSTNAME, serverIP) == 0) //DNSname von HOSTNAME auflösen und in serverIP speichern,
{
http = RedFly.socketConnect(PROTO_TCP, serverIP, 80); // Verbindung zum Server per IP aufbauen
if(http == 0xFF)
{
debugoutln("SOCKET ERR");
RedFly.disconnect();
for(;;); //do nothing forevermore
}
else
{
//HTTP Request senden...
RedFly.socketSendPGM(http, PSTR("GET / HTTP/1.1\r\nHost: "HOSTNAME"/redfly.php?Test=HalloWelt\r\n\r\n")); // HalloWelt per GET (vormals Post) an redfly.php übergeben
}
}
else
{
debugoutln("DNS ERR");
RedFly.disconnect();
for(;;); //do nothing forevermore
}
}
}
}
}
void loop()
{
uint8_t sock, buf[32];
uint16_t rd, len;
//Serial.println("Ausgabe");
if(http == 0xFF) //no socket open
{
return;
}
sock = 0xFF; //0xFF = return data from all open sockets
rd = RedFly.socketRead(&sock, &len, 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
{
//close connection
RedFly.socketClose(sock);
//show http buffer
http_buf[sizeof(http_buf)-1] = 0;
debugout(http_buf);
}
}
}