The module connects properly.
I used the WiServer example to send simple commands to the module via URLs and obtained the proper behaviour from the module (namely get sensor informations in the browser, switch a relay by visiting http://moduleAdress/switch etc.).
The problem is now to be able to send a "complex" packet to the module (a code to be sent by IR to another device). I thought I would use the SocketApp to handle message exchanges, but the SocketApp example is in 2 parts : the ino file that simply handles the Wifi parameters and network startup, and the socketapp.c that handles separately every incoming connection.
I'm looking for a way to get incoming messages available to the main ino class to be able to react to its content (VirtualWire library for RF communication has a get_message function that does exactly what I'd need...)
PaulS:
Define what this "complex" packet looks like.
Complex is not big, it's just a few bytes long (about 20 if I remember correctly). But as it's binary I thought I would pass it as a raw payload on a socket and not as a string on a URL. Beside I don't believe the WiServer lib would handle a variable part in the URL as a php server would.
I thought I would use the SocketApp to handle message exchanges
Why?
Well, I have 2 devices controled by IR signals, so I use 2 "arduinos" as IR relays. One is connected by USB, the other is intended to be connected by WIFI. The one connected by USB is controled by a command line program I wrote, and I thought it would be more convenient to use the same program to communicate with both arduinos. I thought it made more sense to reach it through a socket then (even though the main user interface will be a web page in the end).
and the socketapp.c that handles separately every incoming connection.
"Handles" it how? It must store data somewhere.
Here is the relevant part of the example code, handling the connection :
void socket_app_appcall(void)
{
/*
* The uip_conn structure has a field called "appstate" that holds
* the application state of the connection. We make a pointer to
* this to access it easier.
*/
struct socket_app_state *s = &(uip_conn->appstate);
/*
* If a new connection was just established, we should initialize
* the protosocket in our applications' state structure.
*/
if(uip_connected()) {
PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
}
/*
* Finally, we run the protosocket function that actually handles
* the communication. We pass it a pointer to the application state
* of the current connection.
*/
handle_connection(s);
}
static int handle_connection(struct socket_app_state *s)
{
PSOCK_BEGIN(&s->p);
PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
PSOCK_READTO(&s->p, '\n');
PSOCK_SEND_STR(&s->p, "Hello ");
PSOCK_SEND_STR(&s->p, s->inputbuffer);
memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
PSOCK_CLOSE(&s->p);
PSOCK_END(&s->p);
}
It stores information in a structure defined in the library. But it creates the structure for each incomming connection (which seems logical) and destroys it afterwards, so I have no handle to it from my main ino code... I'd like to be able to transmit the s->inputbuffer content to the ino part, but I don't have a handle to the ino fonctions from the c file either.
I'd like to be able to transmit the s->inputbuffer content to the ino part, but I don't have a handle to the ino fonctions from the c file either.
But, you do have access to all the global variables defined in the sketch. Have the socket code set a flag and copy the buffer. Have loop() check the flag and use the buffer.