I’m having trouble with TCPclient.connect, I’ve searched the forums for working TCPclient.connect code, and some users posted code that said worked for them:
Sorry if the formatting is a bit messy. When I check on the datacloud variable, it is always 30. Which means that client.connect is NEVER returning true :< how can I fix this? I need it to connect to a server that I’m hosting, but I thought I’d stick with getting it to connect in this instance first since it would be easy to alter it afterwards.
I would check your DNS first using this great tool
client.print is very slow and causes a few problems, so client.write is a much better way of doing things.
There is also a library for this type of connection too, adds some nice features. I updated it to use the client.write method a while ago so its nice and quick, you can fine the .h and .cpp files here have a look at the HTTPclient library on the web IDE for example and how to use it.
I updated my cc3000 based off a post I saw in the DNS tool link you posted and that allowed me to get a connection to google.com using the code in my first post. However, I still can’t connect to my own server, or other small server (based off of google app engine). I am using your http code at the moment (from the other link you mentioned), here is what I’ve got:
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
//call once
void setup() {
Spark.variable("datavalue", &datacloud, INT);
Serial.begin(9600);
//datacloud = 10;
}
void loop() {
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "http://py-scis.appspot.com";
request.port = 80;
request.path = "/containerpost";
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.print(response.status);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
delay(10000);
}
The code works just fine if I change it to google.com, but I’m using google’s appengine to host a website and I need it to connect to the server mentioned in the above code. I don’t think it could involve a DNS issue since I updated the CC3000. What are your thoughts? Maybe I’m not doing the request the right way?
I would try with just “py-scis.appspot.com” instead, leaving off the “http://” part. This is a host with many names and the web server on it needs to know which hostname you meant to connect to so the Host: field is critical.