Kuba5
May 8, 2014, 1:56pm
1
Hi,
I Have Arduino Uno with Ethernet Module and I want to measure the temperature every 10 minutes and send it via ethernet module to web in PHP and then to MySQL. Already I have working code for measuring temp. and sending on web, but it meas. and send only when i start Serial Console.
As I said, I want to measure temp. and send it every 10 minutes.
Please, can someone change code for me? Thank you
Here is working code with Serial Console:
#include <UIPEthernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 10, 0, 0, 177 };
char server[] = { "www.jakubmiga.eu"}; // Google
EthernetClient client;
void setup()
{
double fTemp;
double therm = Thermister(analogRead(A0)); // Read sensor
Serial.begin(9600);
Serial.println("Zacinam...");
Ethernet.begin(mac);
client.connect(server, 80);
delay(500);
Serial.println("Pripojuji...");
if (client.connected()) {
Serial.println("Pripojeno");
client.print("GET /add_temp.php?temp=");
client.print(therm);
client.println(" HTTP/1.1");
client.println("Host: www.jakubmiga.eu");
client.println();
} else {
Serial.println("Pripojeni nenavazano");
}
}
void loop()
{
if (client.available()>0) {
char c = client.read();
Serial.print(c);
}
if (0 == (millis()%1000))
Serial.println(millis()); //debug output
if (!client.connected()) { //never true
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
but it meas. and send only when i start Serial Console.
That almost always means that you are underpowering the Arduino with Ethernet shield.
Please, can someone change code for me?
Code changes are not going to cause your power supply to put out more current.
In this case I think the problem is that the line double therm = Thermister(analogRead(A0)); // Read sensor and the code to send transmit the result is in setup() rather than in loop().
...R
Kuba5
May 8, 2014, 3:54pm
4
Ok,thanks, I connected 12V 2A power supply and It works.
Can you help me with code now? If I Want send temperature I have to reset Arduino but i want do it in code.
Thank you
Kuba5
May 8, 2014, 4:24pm
5
So i tried to put the code to void loop, It works partly. It repeats but without PHP request.
This is my source code:
#include <UIPEthernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 10, 0, 0, 177 };
char server[] = { "www.jakubmiga.eu"}; // Google
EthernetClient client;
double fTemp;
double therm = Thermister(analogRead(A0)); // Read sensor
void setup()
{
Serial.begin(9600);
Serial.println("Starting...");
Ethernet.begin(mac);
}
void loop()
{
client.connect(server, 80);
delay(500);
Serial.println("Connecting...");
if (client.connected()) {
Serial.println("Connected");
client.print("GET /add_temp.php?temp=");
client.print(therm);
client.println(" HTTP/1.1");
client.println("Host: www.jakubmiga.eu");
client.println();
} else {
Serial.println("Connect failed");
}
if (client.available()>0) {
char c = client.read();
Serial.print(c);
}
if (0 == (millis()%1000))
Serial.println(millis()); //debug output
if (!client.connected()) { //never true
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
And in Serial Monitor.
Starting...
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
Connecting...
Connected
It's really in loop, but as you can see, it's just connected but it doesn't use PHP request.
What is this for(;;) supposed to so. Isn't it an endless loop?
What is this if (0 == (millis()%1000)) supposed to do?
Can you describe in English the sequence of things that should happen within loop() including how often they should happen.
At the moment the code seems confused (and confusing).
...R
It hardly makes sense to read the temperature once, and then send that value over and over.
Read the damned value in loop()!
Kuba5
May 9, 2014, 8:56am
8
Ok, here is repaired code:
#include <UIPEthernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 10, 0, 0, 177 };
char server[] = { "www.jakubmiga.eu"}; // Google
EthernetClient client;
void setup()
{
Serial.begin(9600);
Serial.println("Starting...");
Ethernet.begin(mac);
}
void loop()
{
double fTemp;
double therm = Thermister(analogRead(A0)); // Read sensor
client.connect(server, 80);
delay(500);
Serial.println("Connecting...");
if (client.connected()) {
Serial.println("Connected");
client.print("GET /add_temp.php?temp=");
client.print(therm);
client.println(" HTTP/1.1");
client.println("Host: www.jakubmiga.eu");
client.println();
} else {
Serial.println("Connect failed");
}
if (client.available()>0) {
char c = client.read();
Serial.print(c);
}
if (0 == (millis()%1000))
Serial.println(millis()); //debug output
}
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
It works good but I want measure and send temperature EVERY 5 minutes.
Put delay to loop is not good idea, It does not periodically works.
Thanks
The questions I asked in Reply #5 may still be relevant.
To manage the timing you need to use the technique in the Blink Without Delay example sketch. I wrote an extended demo in the first post in this Thread .
...R
Kuba5
May 9, 2014, 1:10pm
10
Example BlinkWithoutDelay works great.
Thank you!
hi there why not using emocms on a rapsberry pi, works great for me.
for some example how i did it look at Strange output, but why and how to solve it - Programming Questions - Arduino Forum