Go Down

Topic: The sketch not work when I desconenct yun from usb pc (Read 685 times) previous topic - next topic

oscarcuenca2

Hi
I have loaded a sketch that is working perfect when I have my Yun connected to PC with microUSB but when I disconnect it from PC it does not work, it is like the sketch not begin to work.

The sketch connect with some files I have in linux yun side and make a http connection to MySQL in a remote server, (all these has been tested and it is working well). I have make some test with wifi and it is ok, I have connected to yun with putty and connection was ok. Also I loeaded the scketch via WIFI after reset it and it was ok,it was uploaded correctly, but the sketch does not initialised via wifi.

Maybe have some relationship with bootloader? How Can I solve it? it is like when I try to execute the sketch with no wires (with wifi) the sketch gets frozen... :smiley-confuse:
Any help will be welcome
Thanks friends.
Óscar

ShapeShifter

This construct is very often used in example code:

Code: [Select]
  while (!Serial);

Do you have this in your sketch? If so, get rid of it, as it is the most common cause of a sketch not working when not connected to a PC.

That line of code will wait until a Serial Monitor connection is made - until that happens the sketch will sit in an infinite spin loop. That construct is handy if the sketch is printing out debug information that you don't want to miss while you are making an initial connection, but it's very counter-productive for a stand-alone system.

oscarcuenca2

Hi ShapeShifter
Thanks for your reply
I tried it. The the Yun send tow readings to the remote sensor and stopped for ever. Even I upload the sketch it does not answer back. Just silcence.

temperature and humidity + code of sensor + timestamp.-(data recorder in sqlite and mysql remote-.

1) 20 32 C-136a660f-5af4-4d4d-820e-67af81c912ff  2016-07-03 14:01:56

2) 18 30 C-136a660f-5af4-4d4d-820e-67af81c912ff 2016-07-03 14:05:17

Here is the sketch

#include <Bridge.h>
#include <HttpClient.h>
#include <YunClient.h>
#include <YunServer.h>
#include <DHT.h>
#include <Process.h>

#define DHTPIN 2     // pin de salida(outpin)
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
 
 Bridge.begin();
 Serial.begin(9600);
 Serial.println("DHT11 test!");

dht.begin();
//while(!Serial);

}
void loop() {
// Initialize the client library
 HttpClient client;
int humedad = dht.readHumidity();
int temperatura = dht.readTemperature();


// Make a HTTP request:

  if (isnan(temperatura) || isnan(humedad)) {
   Serial.println("Failed to read from DHT");
 } else {
   Process p;              
   p.begin("/root/curl.sh");      
   p.addParameter(String(temperatura));
   p.addParameter(String(humedad));
   p.run();
   Serial.print("Humedad: ");
   Serial.print(humedad);
   Serial.print(" %\t");
   Serial.print("Temperatura: ");
   Serial.print(temperatura);
   Serial.println(" *C");
 }
delay(200000);  
Serial.flush();
}

oscarcuenca2

Hi ShapeShifter
Thanks for your reply

Finally I get it. It was exactlly what you said. After getting  rid of itwhile (!Serial);, at the beginning I did not catch data, but it was because my MicroUSB is not making good contact and sometimes get off the power and comeback, but after ensuring power is ok, the data began to flow to BBDD perfectlly.

Thanks for your help-
Óscar :)

Go Up