Serial commands

I just have a quick questions. Will Serial commands work even though the arduino is not hooked up to a serial monitor? Example:

Serial.println(F("AT+CGSOCKCONT=1,"IP","m2m005067.attz""));
Serial.flush();
while(Serial.read()!='K');

Will this still send out AT commands when a serial monitor is not hooked up. Will the Arduino just read the serial output regardless? Thanks.

Yes.

Pete

What about if there is no serial port hook u, i.e. USB?

yes the serial data is send always when execute the serial write instruction ... if you want to see the serial data send by the controller then you need to open the serial monitor.. but the data send even if you do not open the serial monitor

Thank you for the replies. I am also curious do I need to have the arduino connected to the serial port on my computer? What I am needing to do is send AT commands with the arduino not connected to the computer, but at a sense station. I am thinking that the serial.read() will not work if it is not connected to the serial port of a computer.

scottycss2000:
I am thinking that the serial.read() will not work if it is not connected to the serial port of a computer.

Why do you think that?

Doesn't Serial.read() read the data coming in from the serial port? If so, what would it be reading if the arduino is not connected to a serial port. The reason I am asking all of this is I am wanting to send sensor data to our website and it was working when the arduino was hooked up to the computer, but when it is not, we are not receiving data. Thanks.

scottycss2000:
Doesn't Serial.read() read the data coming in from the serial port? If so, what would it be reading if the arduino is not connected to a serial port. The reason I am asking all of this is I am wanting to send sensor data to our website and it was working when the arduino was hooked up to the computer, but when it is not, we are not receiving data. Thanks.

Serial.read( ) reads from a serial connection. There are equipment other than PCs with serial ports.

I realize that there are other equipment wit serial ports. I was using of as example. If you look at my earlier question, I asked if no serial port is connected

scottycss2000:
I realize that there are other equipment wit serial ports. I was using of as example. If you look at my earlier question, I asked if no serial port is connected

Again, why do you think it wouldn't work? ? ?

You seem to be confusing the Serial Monitor with a serial port. The Serial Monitor is software. You tell it which serial port to use.

No I am not confusing the two. I know they are different. I wanted to know what would happen in both instances, hence the two separate questions.

scottycss2000:
No I am not confusing the two. I know they are different. I wanted to know what would happen in both instances, hence the two separate questions.

If you wrote a short Arduino program to try it out you would have the answer long before this. The Arduino is great for learning-by-doing.

…R

In a setup with only RX, TX and ground, the micro (e.g. the 328 on an Uno) that uses those pins has no way of knowing if something is connected or not. So that micro will send and (attempt to) read.

I did notice on my Sparkfun Redboard however that the tx light stops flashing when the usb cable is not connected to the PC. This does NOT indicate that the 328 no longer transmits. You can hook up a LED and a resistor to the TX pin and check what it does if the USB is disconnected and the Arduino program is transmitting.

My code works fine when everything when hooked to a serial port on my computer. When I have it powered by battery and not connected to the computer however, no data is transmitted thru my gprs shield.

scottycss2000:
My code works fine when everything when hooked to a serial port on my computer. When I have it powered by battery and not connected to the computer however, no data is transmitted thru my gprs shield.

You do realize that you are raising a different issue, right?

How do you know your battery has enough power to power the Arduino and the shield and whatever else you have connected?

and/or
How do you know your Arduino code is sending the correct commands to the shield?
It won't respond if the messages or formatting are incorrect...

We are using a 12V rechargeable battery with plenty of power. the gprs is running, but nothing is sent. This is the portion of my code that transmits my data to our server. Like I have already stated, it works fine when hooked to the usb port on my computer, but when connected to our battery and no serial port connection to pc or any other device, it does not transmit.

//void send_data()
{
char data[400];
int data_size;
int x = 0;
char server="echo-project-marcusjwhelan.com";
char port="80";

Serial.println(F("AT+CGSOCKCONT=1,"IP","m2m005067.attz""));
Serial.flush();
while(Serial.read()!='K');

Serial.print(F("AT+CHTTPACT="")); //Connects with the HTTP server
Serial.print(server);
Serial.print(F("","));
Serial.println(port);
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data=Serial.read();
x++;
}while(!(data[x-1]=='T'&&data[x-2]=='S')); //waits for response "REQUEST"

Serial.print(F("GET /insert?name=windy"));
Serial.print(F("&long=-"));
Serial.print(longitude);
Serial.print(F("&lat="));
Serial.print(latitude);
Serial.print(F("&hum="));
Serial.print(humidity);
Serial.print(F("&temp="));
Serial.print(tempf);
Serial.print(F("&dew="));
Serial.print(dew);
Serial.print(F("&pres="));
Serial.print(pres);
Serial.print(F("&speed="));
Serial.print(windspeed);
Serial.print(F("&dir="));
Serial.print(winddir);
Serial.println(F(" HTTP/1.1"));
Serial.println(F("Host: echo-project-marcusjwhelan.com"));
Serial.println(F("Content-Length: 0"));
Serial.println(F("\r\n\r\n"));
Serial.write(0x1A); //sends ++
Serial.write(0x0D);
Serial.write(0x0A);

while(Serial.read()!='K');
while(Serial.read()!=' ');

Serial.print(data);
Serial.flush();
//

I can't see your formatted source...

Handling your data character by character is fraught with risk...
Why not format and buffer it before sending... and the same when receiving...?

HTTP POST may offer some advantages as well.

We are using multiple sensor inputs and need to have their values sent with the GET request. It works fine with the server we have. Do have an example of what you are suggesting?

Can you please edit your post with the code and embed the code in code tags;
** **[code]** **
your code here
** **[/code]** **
will result in

your code here

Thank you

Next, can you provide a diagram (or a photo/scan of a hand drawn diagram) how everything is wired?

And what is this doing?

Serial.write(0x1A);       //sends ++

Although it's ascii, it's not text and the webserver will probably not know what to do with it.