Well your cool el_supremo, And since im doing this for FUN and not for MONEY(Cause my only goal is to make this little guy
trip to see is picture on a 1,8" screen) I’ll share what i’ve done allready.
So here what i’ve done so far, It’s running the socketapp client for a CuHead wifi Shield the thing already connect on the local network and on my computer, then request it’s first line and my computer send it, all that is fine:
#include <WiShield.h>
#include <string.h>
extern "C" {
#include <uip.h>
}
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#include <UTFT.h>
#include <avr/pgmspace.h>
UTFT myGLCD(ITDB18SP,6,5,2,3,4); // Remember to change the model parameter to suit your display module!
unsigned char local_ip[] = {192,168,1,10}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[] = {"TheNetwork"}; // max 32 bytes
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
const prog_char security_passphrase[] PROGMEM = {"nceton123"}; // max 64 characters
int X
int Y
char R
char G
char B
prog_uchar wep_keys[] PROGMEM = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0, 0x12, 0x34, 0x56, 0x78, 0x9A, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
boolean connectToServer(void);
char header[] = "POST /tutorial/showBrowser.jsp HTTP/1.0\r\nContent-Length: 10000\r\n\r\n";
unsigned int xmitCount = 0;
boolean connectedToServer = false;
boolean inited = false;
unsigned long nextXMitTime;
char buffer[105];
long previousMillis = 0;
long interval1 = 20000;
void setup() {
// Serial.begin(57600);
// Serial.println("starting");
pinMode(9, INPUT_PULLUP);
connectedToServer = false;
WiFi.init();
myGLCD.InitLCD(PORTRAIT);
}
void loop() {
WiFi.run();
if(millis() - previousMillis > interval1) {
previousMillis = millis();
if (digitalRead(9) == LOW){WiFi.init();}
}
if (millis() > nextXMitTime && inited && !connectedToServer) {
// Serial.print("Connecting to server... ");
xmitCount = 0;
if (connectToServer()) {
connectedToServer = true;
// Serial.println("connection OK");
}
else {
// Serial.println("connection NOT OK");
}
}
}
// Make the initial connection to the remote server at 192.168.0.2
boolean connectToServer(void){
struct uip_conn *conn;
uip_ipaddr_t ipaddr;
uip_ipaddr(&ipaddr, 192,168,0,2);
conn = uip_connect(&ipaddr, HTONS(8080));
return (conn != NULL);
}
extern "C" {
void socket_app_init() {
// Serial.println("inited!!!");
inited = true;
nextXMitTime = millis();
}
// Called by the framework when there's an event which needs attention
// Here's where the work gets done.
void socket_app_appcall() {
// A connection was just made and it's OK to send data.
if (uip_connected()) {
// Serial.println("{connected}");
uip_send(header, strlen(header));
}
// connection was broken. Perhaps server went down or cable unplugged? Retry immediately
if (uip_aborted()) {
// Serial.println("{aborted}");
connectedToServer = false;
}
// connection timed out. Not good but we can try again. Retry immediately
if (uip_timedout()) {
// Serial.println("{timedout}");
connectedToServer = false;
}
// connection was closed. This is usually expected after the transaction is complete
// It seems we'll get this once with the UIP_NEWDATA flag set, and then again with the
// UIP_NEWDATA cleared. We only want to advance 'nextXMitTime' once, so we ignore the
// UIP_CLOSED unless it has no new data
if(uip_closed() && !uip_newdata()) {
// Serial.println("{closed}");
connectedToServer = false;
nextXMitTime += 30000L; // XMit again in 30 seconds
}
// An error occurred and we need to retransmit.
if (uip_rexmit()) {
// Serial.println("{retransmit}");
uip_send(buffer, strlen(buffer));
}
// The current packet is done being transmitted and now we're OK to transmit another packet.
if (uip_acked()) {
if (xmitCount < 20) {
// Serial.print("xmit: ");
// Serial.println(xmitCount, DEC);
// Build a string that is 100 lines long
// We can actually transmit a packet up to the size of 'uip_mss()', which is tyipcally 327 bytes.
sprintf(buffer, "Prêt à recevoir\r\n", xmitCount);
xmitCount += strlen(buffer);
uip_send(buffer, strlen(buffer));
}
else { // send another linefeed to indicate the end of this POST data.
if (uip_connected()) {
uip_send("\r\n", 2);
}
}
}
// here's where new data arrives. Do any string processing here.
if(uip_newdata()) {
String mydata =""
unsigned int len = uip_datalen();
myGLCD.setColor (R,G,B);
myGLCD.drawPixel(X,Y);
// Serial.write((const uint8_t*)uip_appdata, len);
while (uip_appdata != '.') {
mydata += uip_appdata
}
for
}
}
}
But spécificaly this part is important:
// here's where new data arrives. Do any string processing here.
if(uip_newdata()) {
String mydata =""
unsigned int len = uip_datalen();
// myGLCD.setColor (R,G,B); //These to will go in a for { } once the 3 arrays will be build
// myGLCD.drawPixel(X,Y); //These to will go in a for { } once the 3 arrays will be build
// Serial.write((const uint8_t*)uip_appdata, len);
while (uip_appdata != '.') {
mydata += uip_appdata
}
for
}
}
The Data come well, Line by line and i allready know how I will ask for the next line, it’s already programe in my computer application. But that’s it for now it’s just a buntch of R,G,B,R,G,B, And i know the lise is over when i find a " . ". And althouht ill probably figure it out while im dreaming tonight. I would like to go the sleep with a peacefull mind lol
