@Dave That’s good to know. So Spark.process() calls are not important.
@bko I’ve changed it to send a packet to google.com, and I still don’t see anything in wirehsark indicating a packet was actually sent.
Maybe someone better versed in the firmware can tell me if there’s some kind of diference between manual mode and automatic mode. Connecting to the cloud while in manual mode seems to cause the code to crash after a few seconds with a flashing red indicator. This doesn’t happen in manual mode without the cloud connection. Diagnostic page seems to indicate one flash is a hard fault.
EDIT: Switching to Automatic mode and removing the WiFi setup code also appears to crash the Core in the same method as described above. Again, no evidence of packets actually being sent. What could be causing this?
It appears to work up until it sucessfully manages to connect to google.com. Then it hard faults, and the cycle repeats. Infuriating.
Has anyone been able to send a TCP packet in manual mode? Wouldn’t this be one of the first tests of the manual mode itself? Here’s the test code again:
SYSTEM_MODE(MANUAL);
// EXAMPLE USAGE
unsigned int once = 0;
TCPClient client;
IPAddress addr( 0, 0, 0, 0 );
byte server[] = { 192, 168, 1, 254 };
void setup()
{
// Make sure your Serial Terminal app is closed before powering your Core
Serial.begin(9600);
WiFi.on();
// Connects to a network with a specified authentication procedure.
// Options are WPA2, WPA, or WEP.
WiFi.clearCredentials();
//WiFi.setCredentials("DIRECT-thQ0:DSC-QX10", "1R7WJZ7U", WPA2);
WiFi.setCredentials("Why", "me?", WPA);
WiFi.connect();
// while(!Serial.available()) Spark.process();
while (!WiFi.ready()) {
Serial.println("Waiting for WiFi...");
Spark.process();
delay(1000);
}
}
void loop()
{
Spark.process();
addr = WiFi.localIP();
WiFi.ping(WiFi.gatewayIP());
Serial.println(addr);
if ((addr[0] != 0 ||addr[1] != 0 || addr[2] != 0 || addr[3] != 0) && (once == 0))
{
//If IP Address, Connect to CLoud
Spark.connect();
Spark.process();
Serial.println("Connected to Cloud")
}
if (addr[0] != 0 ||addr[1] != 0 || addr[2] != 0 || addr[3] != 0)
{
Spark.process();
//"http://10.0.0.1/sony/camera"
if (client.connect("www.google.com", 80))
{
Serial.println("Connected");
//Encodes JSON Data so that the camera will understand it.
//Also adds POST data and sends packet
//String request = "{\"method\": \"actTakePicture\", \"params\":\"[]\", \"id\": \"1\", \"version\": \"1.0\"}";
String request = "test";
client.println("POST HTTP/1.1");
client.println("Host:192.168.1.254");
client.println("Accept:*/*");
client.print("Content-Length: ");
client.println(request.length());
client.println("Content-Type:application/x-www-form-urlencoded");
client.println(request);
//Serial.println(request);
client.println();
Spark.process();
client.flush();
client.stop();
Spark.process();
once = 1;
Serial.println("Packet Sent");
delay(500);
}
else
{
Serial.println("Connection Failed");
Spark.process();
}
}
if (client.available())
{
char c = client.read();
Serial.print(c);
Spark.process();
}
// if (!client.connected())
// {
// Serial.println();
// Serial.println("disconnecting.");
// client.stop();
// for(;;);
// }
}
Automatic Code
// SYSTEM_MODE(MANUAL);
// EXAMPLE USAGE
unsigned int once = 0;
TCPClient client;
IPAddress addr( 0, 0, 0, 0 );
byte server[] = { 192, 168, 1, 254 };
void setup()
{
// Make sure your Serial Terminal app is closed before powering your Core
Serial.begin(9600);
// WiFi.on();
// // Connects to a network with a specified authentication procedure.
// // Options are WPA2, WPA, or WEP.
// WiFi.clearCredentials();
// //WiFi.setCredentials("DIRECT-thQ0:DSC-QX10", "1R7WJZ7U", WPA2);
// WiFi.setCredentials("TechShop WiFi", "creative", WPA);
// WiFi.connect();
// while(!Serial.available()) Spark.process();
while (!WiFi.ready()) {
Serial.println("Waiting for WiFi...");
// Spark.process();
delay(1000);
}
}
void loop()
{
// Spark.process();
addr = WiFi.localIP();
WiFi.ping(WiFi.gatewayIP());
Serial.println(addr);
// if ((addr[0] != 0 ||addr[1] != 0 || addr[2] != 0 || addr[3] != 0) && (once == 0))
// {
// //If IP Address, Connect to CLoud
// Spark.connect();
// Spark.process();
// Serial.println("Connected to Cloud")
// }
if (addr[0] != 0 ||addr[1] != 0 || addr[2] != 0 || addr[3] != 0)
{
// Spark.process();
//"http://10.0.0.1/sony/camera"
if (client.connect("www.google.com", 80))
{
Serial.println("Connected");
//Encodes JSON Data so that the camera will understand it.
//Also adds POST data and sends packet
//String request = "{\"method\": \"actTakePicture\", \"params\":\"[]\", \"id\": \"1\", \"version\": \"1.0\"}";
String request = "test";
client.println("POST HTTP/1.1");
client.println("Host:192.168.1.254");
client.println("Accept:*/*");
client.print("Content-Length: ");
client.println(request.length());
client.println("Content-Type:application/x-www-form-urlencoded");
client.println(request);
//Serial.println(request);
client.println();
// Spark.process();
client.flush();
client.stop();
// Spark.process();
once = 1;
Serial.println("Packet Sent");
delay(500);
}
else
{
Serial.println("Connection Failed");
// Spark.process();
}
}
if (client.available())
{
char c = client.read();
Serial.print(c);
// Spark.process();
}
// if (!client.connected())
// {
// Serial.println();
// Serial.println("disconnecting.");
// client.stop();
// for(;;);
// }
}