Ok, so it works... much appreciation for the assistance. karma to both of you.
I did however have to add a bit for it to "work" that is, the client.stop(). It "works" now but.... I must have a memory leak somewhere. after multiple successful attempts of changing the state of the light... the program stops in a manner that causes me to have to reset the arduino.
This is the function that I used including the added client.stop().
void phoneyTV(boolean status)
{
if (client.connect(myserver, 3480)) //starts client connection, checks for connection
{
Serial.println(F("connected"));
client.print(F("GET /data_request?id=action&output_format=xml&DeviceNum=88&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue="));
client.print(status ? F("1") : F("0"));
client.println(F(" HTTP/1.1"));
client.println(F("Connection: close")); //close 1.1 persistent connection
client.println(); //end of get request
delay(1);
client.stop();
}
}
entire sketch attached. I have to hunt down the culprit.
Have you included a way to check the socket status? Here is mine. Call it when you are going to connect and send a request to see if there is a socket available.
#include <utility/w5100.h>
byte socketStat[MAX_SOCK_NUM];
void ShowSockStatus()
{
for (int i = 0; i < MAX_SOCK_NUM; i++) {
Serial.print(F("Socket#"));
Serial.print(i);
uint8_t s = W5100.readSnSR(i);
socketStat[i] = s;
Serial.print(F(":0x"));
Serial.print(s,16);
Serial.print(F(" "));
Serial.print(W5100.readSnPORT(i));
Serial.print(F(" D:"));
uint8_t dip[4];
W5100.readSnDIPR(i, dip);
for (int j=0; j<4; j++) {
Serial.print(dip[j],10);
if (j<3) Serial.print(".");
}
Serial.print(F("("));
Serial.print(W5100.readSnDPORT(i));
Serial.println(F(")"));
}
}
A socket status list:
0X0 = available.
0x14 = socket waiting for a connection
0x17 = socket connected to a server.
0x1C = socket connected waiting for close.
0x22 = udp socket.
ShowSockStatus doesn't return anything. It displays the socket status for all sockets. If none of the sockets show show a status of 0x0, then the client.connect call will fail.
void phoneyTV(boolean status)
{
ShowSockStatus();
if (client.connect(myserver, 3480)) //starts client connection, checks for connection
{
SurferTim:
ShowSockStatus doesn't return anything. It displays the socket status for all sockets. If none of the sockets show show a status of 0x0, then the client.connect call will fail.
void phoneyTV(boolean status)
{
ShowSockStatus();
if (client.connect(myserver, 3480)) //starts client connection, checks for connection
{
thanks Tim,
In addition to adding your function I broke up this:
into smaller bits as in the function that I am now using (below). I noticed that the demos used multiple print() functions versus sending one long (flash-stored) string. It occurred to me that those large strings had two work their way through the stack and perhaps that was what was stalling my program. Well, so far, much better.