Does the function shown at the bottom of this post work if its server parameter is an IP address and port parameter is 3000?
(The same function does work if the server parameter is a url (like x.com) address and port parameter is 80)
In detail:
I am trying to post a sensor value from the Spark Core to messaging engines on two servers, one commercial server with a URL listening to port 80 (lets call it ServerURL80), and the other one a VPS (Virtual Platform Server) with fixed IP listening on port 3000 (lets call this ServerIP3000).
The code I have uses the getrequest function below. It works fine and I can see data on the messaging engine on ServerUrl80 when I call getrequest fwith server set to url of the ServerUrl80, and the url to the publishing data, and port set to 80.
The same function doesn’t work for ServerIP3000 when I call getrequest with server set to the ip address of the ServerIP3000, and the url to the publishing data (same as above), and port set to 3000.
To make sure that nothing is wrong on the server side of the ServerIP3000, I used the HttRequester plugin for Firfox and can successfully publish data to it.
That razed a new dumb question: How can I see the Serial.print messages? I don’t know how to run something like Serial Monitor (for Arduino) to see it’s messages over usb on my PC.
Could it be that you know where on the Spark Doc I can find info about that (the Spark Doc doesn’t seam to have Search function)?
To get the serial port started you will need this in you setup loop
Serial.begin(115200);
while (!Serial.available());
while (Serial.available()) {Serial.read();}//throw it away
then you can use the arduino terminal to connect, once the core connects to the cloud and the user firmware starts running it will show up. check the baud rate is correct too. Once you have connected, if you close the window and try and open it again it will give a port already open error. and with the arduino terminal you cant just push enter to start the connection you have to write some text and push enter (the while (!Serial.available() bit waits for you to open the terminal and type something.
so if you want an easy way to turn it on and off put it in a if statement and use a pin to toggle it on or off at startup time… if you have the jumper betwwen D0 and gnd it will give the output, otherwise it wont and will run normally. I wouldnt turn it on and off once its running unless you call a function with the pin to start the serial otherwise it might have a fit if you call serial.print without the port started, get what im saying?
int DEBUGpin = D0; // Debug switch connects to D0 on the core
boolean DEBUG = false; // enable or disable Debug
in setup loop
pinMode(DEBUGpin , INPUT_PULLUP);
delay(500);
if(digitalRead(DEBUGpin) == LOW) DEBUG = true;
if(DEBUG) {
Serial.begin(115200);
while (!Serial.available());
while (Serial.available()) {Serial.read();}//throw it away
}
I have found Serial.flush() doesnt work for me so i use the line marked throw it away above which does what the serial flush is meant to do…
One other thing is the way the ‘server’ is stored, if i use an address like something.com i will use a char array where if its an ip the i use a byte array ie