I am a newbie to sparkcore. So please pardon me if this query sounds petty to you.
I want to go to a webpage from my core. Once I go to the page, I can send a message to my mobile via Twillio.
However, I am not very sure now do I approach to this problem of going to a webpage using my spackcore. I read a few forums about this, but being very new to this, could not follow much. Could anyone please guide me a bit with basics?
// SYNTAX
TCPClient client;
// EXAMPLE USAGE
TCPClient client;
byte server[] = { 74, 125, 224, 72 }; // Google
void setup()
{
// Make sure your Serial Terminal app is closed before powering your Core
Serial.begin(9600);
// Now open your Serial Terminal, and hit any key to continue!
while(!Serial.available()) SPARK_WLAN_Loop();
Serial.println("connecting...");
if (client.connect(server, 80))
{
Serial.println("connected");
client.println("GET /search?q=unicorn HTTP/1.0");
client.println("Host: www.google.com");
client.println("Content-Length: 0");
client.println();
}
else
{
Serial.println("connection failed");
}
}
void loop()
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;);
}
}
I tried with the forums you suggested and things are working now.
However, I had a query. Why are we always using the command “Serial.begin(9600)” in the setup loop. Is there a way to have some provision so that we need to have to open a serial monitor and press enter?
For my application, I would like to avoid pressing enter while I start.
@nj187, if you dont need to use the Serial port, you can remove this code:
// Make sure your Serial Terminal app is closed before powering your Core
Serial.begin(9600);
// Now open your Serial Terminal, and hit any key to continue!
while(!Serial.available()) SPARK_WLAN_Loop();
The while() line is the one that waits for you to hit a key to continue because the Spark so fast, messages that print out in setup go out before you have time to open your serial monitor! If that’s ok but you still have other messages printing to serial, just remove the while() line.