[SOLVED] Impossible to comply the example code for arduino YUN

Hello,
I have download the library of arduinoYUN from your site, and I try the example of SaveValue, however, I could not comply the code.
The error messages are :smile:

 Arduino: 1.7.11 (Mac OS X), Board: "Arduino Yún"

In file included from UbidotsGetValue.ino:1:0:
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.h:29:21: fatal error: Process.h: No such file or directory
 #include <Process.h>
                     ^
compilation terminated.
Error compiling..

Could you please tell me what to resole this problem, please?
My arduino Yun is arduino.org with linino, I don’t know is that related with this problem? Thank you for your attention.
Best regards,
He

I strongly recommend using Ubidots’ MQTT broker. The Yun’s bridge library is very unstable.

See http://jpmens.net/2013/10/15/mqtt-on-the-arduino-yun/ and the details about MQTT for Ubi: https://ubidots.com/docs/api/index.html#authentication27

hello @imhenri that error is an error in YUN library, and i can see that you are using a Beta version of Arduino, try to download the stable version for MAC.

Best regards,
Metavix

I have changed to another arduino version (one of arduino.cc), but it does not work neither.
Could you please let me know your version?

Arduino: 1.6.12 (Mac OS X), Board: "Arduino Yún"

/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.cpp:31:1: error: prototype for 'Ubidots::Ubidots(char*)' does not match any in class 'Ubidots'
 Ubidots::Ubidots(char* token) {
 ^
In file included from /Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.cpp:26:0:
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.h:42:7: error: candidates are: constexpr Ubidots::Ubidots(Ubidots&&)
 class Ubidots {
       ^
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.h:42:7: error:                 constexpr Ubidots::Ubidots(const Ubidots&)
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.h:44:16: error:                 Ubidots::Ubidots(char*, char*)
       explicit Ubidots(char* token, char* server = SERVER);
                ^
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.cpp: In member function 'void Ubidots::sendAll()':
/Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.cpp:148:41: error: too few arguments to function 'int snprintf(char*, size_t, const char*, ...)'
     snprintf(buffer, "(sleep 1\necho \"");
                                         ^
In file included from /Applications/Arduino.cc.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:24:0,
                 from /Applications/Arduino.cc.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26,
                 from /Applications/Arduino.cc.app/Contents/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/Arduino.cc.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:232,
                 from /Applications/Arduino.cc.app/Contents/Java/libraries/Bridge/src/Bridge.h:26,
                 from /Applications/Arduino.cc.app/Contents/Java/libraries/Bridge/src/Process.h:22,
                 from /Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.h:28,
                 from /Users/HE/Documents/Arduino/libraries/ubidots-arduino-yun-master/UbidotsYUN.cpp:26:
/Applications/Arduino.cc.app/Contents/Java/hardware/tools/avr/avr/include/stdio.h:687:12: note: declared here
 extern int snprintf(char *__s, size_t __n, const char *__fmt, ...);
            ^
exit status 1
Error compiling for board Arduino Yún.

Thank you, I 'll try it.

1 Like

I have similar error on Windows.

@jagstock @imhenri

We fixed a problem in compilation in some pc’s, now it will working fine.
You can download the latest version of the library from github and upload it to YUN.

I apologize for the error it will not happen again.

Best regards,
Metavix

Thanks very much Metavix.
it works now with arduino 1.6.12, but not with the arduino 1.7.11 of arduino.org. it’s really ugly about the separation of these two parts.

Agree, I tried with Windows and Linux and the library worked well, but in Mac it didnt compile. Now it does though, thanks @metavix!

@imhenri i will try to find what is the change of that version of IDE and try to change the library to be compatible to that version.
You are welcome.

Best regards,
Metavix

Hi, I have tried with the method you indicated. But I do not know how to apply the different parameters (broker, topic, data, token…). Do you have some examples to explain how to update the data to ubidots with MQTT and the pubsubclient library, please?

actually, in the arduino.org. they propose the ciao library for different internet connection protocols which contains MQTT. I tried this library with IBM bluemix, but I can’t reach the function with Ubidots.
Here is my configuration of ubidots for update data.

{
	"name" : "mqtt",
	"description" : "MQTT (v3.1) connector for Ciao Core",
	"authors": ["Arduino Team <swdev@arduino.org>"],
	"repository" : "https://github.com/arduino-org/Ciao",
	"version" : "0.0.1",
	"params" : {
		"host" : "mqtt://things.ubidots.com",
		"port" : 1883,
		"username" : "mon token",
		"password" : "",
		"clean_session": true,
		"qos": 1,
		"subscribed_topic": [ "" ],
		"client_id": "",
		"lwt_topic": "",
		"lwt_message": ""
	},
	"log" :{
		"level" : "info"
	}
}

and in my code, I define the mqtt pub_topic and data, like this.

Ciao.write(“mqtt”,"/v1.6/devices/arduinoYun","{“temperature”: {“value”:"+String(temperatureC)+"}}");

Could you tell me which parameters is wrong for me please? or ciao library does not work with MQTT of ubidots?

Here is my code, I have a problem that I applied.
I could create the data source and the variables (however only last variable “humidity”), but there is not update data activities for the variables.
Thanks very much for your help.

here is my code for arduino YUN


/*
 MQTT IOT Example
 - formats the results as a JSON string for the Ubidots example
 - connects to an MQTT server (either local or at the Ubidots Cloud)
 - and publishes the JSON String to the topic named quickstart:MY_MAC_ADDRESS
 */

#include <SPI.h>
 #include <YunClient.h> 
#include <PubSubClient.h> 
#include <Console.h> 

#define TOKEN "my token" 

// Note this next value is only used if you intend to test against a local MQTT server
byte localserver[] = {192, 168, 1, 98 };
// Update this value to an appropriate open IP on your local network
byte ip[]     = {172, 20, 10, 20 };

char servername[]="things.ubidots.com";
char labelDS[]= "MQTTTEST";
String pubTopic  = String("/v1.6/devices/")+labelDS;

float tempF = 0.0;
float tempC = 0.0;
float humidity = 0.0;

YunClient yunClient;

// Uncomment this next line and comment out the line after it to test against a local MQTT server
//PubSubClient client(localserver, 1883, 0, ethClient);
PubSubClient client(servername, 1883, 0, yunClient);

void setup()
{

  // Start the ethernet client, open up Console port for debugging, and attach the DHT11 sensor
  Bridge.begin();
  Console.begin();
  
  // Wait for the Console port to connect
  while (!Console);

}

void loop()
{
//  char clientStr[34];
//  clientName.toCharArray(clientStr,34);
  char topicStr[26];
  pubTopic.toCharArray(topicStr,26);
  getData();
  if (!client.connected()) {
    Console.print("Trying to connect to: ");
    Console.println(TOKEN);
    client.connect(labelDS,TOKEN,"");
  }
  if (client.connected() ) {
    String json = buildJson();
    char jsonStr[200];
    json.toCharArray(jsonStr,200);
    boolean pubresult = client.publish(topicStr,jsonStr);
    Console.print("attempt to send ");
    Console.println(jsonStr);
    Console.print("to ");
    Console.println(topicStr);
    if (pubresult)
      Console.println("successfully sent");
    else
      Console.println("unsuccessfully sent");
  }
  delay(5000);
}

String buildJson() {
  String data = "{";
  data+="\n";
  data+="\"temperature (F)\": ";
  data+=(int)tempF;
  data+= ",";
  data+="\n";
  data+="\"temperature (C)\": ";
  data+=(int)tempC;
  data+= ",";
  data+="\n";
  data+="\"humidity\": ";
  data+=(int)humidity;
  data+="\n";
  data+="}";
  return data;
}

void getData() {
  
    humidity = 20;
    tempF = 30;
    tempC = 40;
    
}

here is the console monitor

attempt to send {
"temperature (F)": 30,
"temperature (C)": 40,
"humiity": 20
}
to /v1.6/devices/MQTTTES
successfully sent

finally, I found the solution, it’s just here the name of the variable can not contains “(”. Thank you.