I am at a loss to understand the problem with uploading sketches on my WiFi port. The sketch below works when I upload through the micro usb port /dev/tty.usbmodem1411 . The sketch logs sensor data to a xively account
#include <Bridge.h>
#include <Console.h>
#include <Process.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define APIKEY "MyAPIKey" // your pachube api key
#define FEEDID 123456789 // your feed ID
#define USERAGENT "Pollution_loggers" // user agent is the project name
// set up net client info:
const unsigned long postingInterval = 60000; //delay between updates to xively.com
unsigned long lastRequest = 0; // when you last made a request
String dataString = "";
void setup() {
// start serial port:
Bridge.begin();
Serial.begin(9600);
dht.begin();
while(!Serial); // wait for Network Serial to open
Serial.println("Xively client");
// Do a first update immediately
updateData();
sendData();
lastRequest = millis();
}
void loop() {
// get a timestamp so you can calculate reading and sending intervals:
long now = millis();
// if the sending interval has passed since your
// last connection, then connect again and send data:
if (now - lastRequest >= postingInterval) {
updateData();
sendData();
lastRequest = now;
}
}
void updateData() {
// convert the readings to a String to send it:
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
dataString = "Temperature,";
dataString += dht.readTemperature(false);
delay(250);
// add pressure:
dataString += "\nHumidity,";
dataString += dht.readHumidity();
int sensorValue1 = analogRead(A2);
delay(100);
int sensorValue2 = analogRead(A5);
dataString += "\nVoltage1,";
dataString += sensorValue1*0.0049;
dataString += "\nVoltage2,";
dataString += sensorValue2*0.0049;
delay(1000);
}
// this method makes a HTTP connection to the server:
void sendData() {
// form the string for the API header parameter:
String apiString = "X-ApiKey: ";
apiString += APIKEY;
// form the string for the URL parameter:
String url = "https://api.xively.com/v2/feeds/";
url += FEEDID;
url += ".csv";
// Send the HTTP PUT request
// Is better to declare the Process here, so when the
// sendData function finishes the resources are immediately
// released. Declaring it global works too, BTW.
Process xively;
Serial.print("\n\nSending data... ");
xively.begin("curl");
xively.addParameter("-k");
xively.addParameter("--request");
xively.addParameter("PUT");
xively.addParameter("--data");
xively.addParameter(dataString);
xively.addParameter("--header");
xively.addParameter(apiString);
xively.addParameter(url);
xively.run();
Serial.println("done!");
// If there's incoming data from the net connection,
// send it out the Serial:
while (xively.available()>0) {
char c = xively.read();
Serial.write(c);
}
}
However, the above sketch does not run when I upload it through the WiFi port (Arduino Yun at 192.168.x.x) even though no error is reported, and the amber RX blinks briefly on the Yun to confirm this. Also, when I go back to usb port and click on Serial Monitor the sketch starts to work again. What is going on here??