[SOLVED] Send multiple variables over Arduino WiFi Shield

Greetings,

I am trying to send multiple variables over Arduino WiFi shield and despite there being a straightforward tutorial on the internet, I am not able to do it.

I have added the additional ID variables. The problem is, I am only able to run the program i.e. I receive data only when I enable single variable posting.
For more than one, it simply hangs.

I have attached the code. Any help is appreciated.

Thank you.

Ubidots_02_Accelerometer.ino (2.9 KB)

Hi @pranshushelat correcting my previous post since I see you are indeed using our library. I also assume you checked if the firmware of your WiFi shield is up to date? otherwise it will have trouble connecting to external servers. See Arduino’s firmware update guide for more information.

Hey! @pranshushelat
How are you?
I will try yo help you. I need some things to help you.

  1. Could you tell me what is the size of your sketch?
  2. What device are you using? (Arduino UNO, What sensor, etc)
    You can find it there:
    http://www.pluggy.me.uk/photo/arduinomegasketch.png

Post here a screenshot with your sketch size.
By the way could you see anything in your serial monitor when you try to use add function more than one time?

Best regards,
Metavix

Hello Metavix, I am good. How about you?

I am using Arduino Mega 2560 with a WiFi shield. The sensor is an accelerometer which gives 6 different signals. This is the screenshot of the program. The size is only 8192 bytes.

Now, with only 1 variable, i.e. only ID1 and value1 transmitting like below,

the data transfer occurs properly and this is the serial monitor:

But with 2 variables, (see the first screenshot), the serial monitor stops at ‘Posting your Variables’ as follows:

Please see if you can help me out here. Thank you so much.

Hello @pranshushelat I uploaded a new branch on Ubidots Arduino library of WiFi. I think that update will solve your problems with Ubidots library. It will be available soon to download by the users.

Best regards,
Metavix

when it will be ready the new version of the library that solves the multivariable save problem??

@zoisdagaris Now it solves the problem
Best regards,
Metavix

Where is the new version of the library. Current version that exists in Github does not solve the problem

@zoisdagaris Are you sure ?

Because the current version is the branch that i built and now is merged with the master branch. Do you have any issue?

The example code is:

#include <SPI.h>
#include <WiFi.h>

#include <UbidotsArduino.h>
#define ID  "Your_variable_ID_here"  // Put here your Ubidots variable ID
#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN


char ssid[] = "yourNetwork"; //  your network SSID (name)
char pass[] = "secretPassword";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

Ubidots client(TOKEN);

void setup(){
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }
    String fv = WiFi.firmwareVersion();
    if (fv != "1.1.0") {
        Serial.println("Please upgrade the firmware");
    }
        
}
void loop(){
        float value = analogRead(A0);
        client.add(ID, value);
        client.add(ID, value);
        client.add(ID, value);
        client.sendAll();
}

it is working for me.
Best regards,
Metavix

not working. Only for one variable WORKS . For more variables do not send anything

for example:

    client.add(ID, 30);
    client.add(ID2, 50);
    client.sendAll();

its not work

@zoisdagaris could you paste here the response of the serial terminal please?

my code is:

//WiFi connection-IoT SERVER-----------------------------------------------------------------------------------
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include “Adafruit_HDC1000.h”
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <UbidotsArduino.h>

#define ID “578ba8e97625423621131d11” // PIR SENSOR
#define ID2 “578ba8ad76254231d9da68d1” // Temperature
#define ID3 “578ba8b676254232a9951854” // Humidiity
#define ID4 “57892043762542463541ad86” // Humidex
#define ID5 “5789204c76254246310c00ef” // light
#define ID6 “-” // Sound
#define ID7 “-” // Force
#define ID8 “-” // Medication
#define ID9 “-” // Product Base
#define ID10 “-” // Relay

#define TOKEN “bROkgjIFJPTYv0g8rFy0dLg5dmY4CM” // Put here your Ubidots TOKEN

char ssid[] = “ZOIS-wireless-LAN”; // your network SSID (name)
char pass[] = “korleone”; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

Ubidots client(TOKEN);

Adafruit_HDC1000 hdc = Adafruit_HDC1000();//Temperature
float humidex;

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);//Light Sensor

//PIR sensor-----------------------------------------------------------------------------------------------------
long unsigned int lowIn; //the time when the sensor outputs a low impulse
long unsigned int pause = 5000; //the amount of milliseconds the sensor has to be low before we assume all motion has stopped
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 45; //the digital pin connected to the PIR sensor’s output
int pirValue=0;
int ledPin = 13;

//Product Base-------------------------------------------------------------------------------------------------
int laserPin =35; //pin for Laser
int lightPin = 11; //pin for Photo resistor
int productStatus;

void setup(){
Serial.begin(9600);

//WiFi connection to IoT server-----------------------------------------

while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
}

String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
}

// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
    Serial.println("Connected to wifi");
     printWifiStatus();
}

//PIR SENSOR SETUP--------------------------------------------------
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);

pinMode(laserPin, OUTPUT);//Product Base

//Temperature & Humidity sensor------------------------------------
Serial.println(“HDC100x test”);

if (!hdc.begin()) {
Serial.println(“Couldn’t find sensor!”);
while (1);
}

//Light Sensor Setup--------------------------------------------------
tsl.begin();

}

void loop(){

//Temperature - Humidity - Humidex data to IoT Server

Serial.println(hdc.readTemperature());
Serial.println(hdc.readHumidity());
humidex = calculate_humidex (hdc.readTemperature(), hdc.readHumidity()); //humidex is calculated
Serial.println(humidex);

//Light Sensor----------------------------------------------------------
sensors_event_t event;
tsl.getEvent(&event);
Serial.print(event.light);

client.add(ID, digitalRead(pirPin));//PIR DATA to IoT Server
client.add(ID2, hdc.readTemperature()); //Temperature
client.add(ID3, hdc.readHumidity()); //Humidity
client.add(ID4, humidex); //Humidex
client.add(ID5, event.light); //Light

client.sendAll();

}

//function to calculete Humidex-----------------------

float calculate_humidex(float temperature,float humidity) {
float e;

e = (6.112 * pow(10,(7.5 * temperature/(237.7 + temperature))) * humidity/100); //vapor pressure

float humidex = temperature + 0.55555555 * (e - 10.0); //humidex
return humidex;

}

//function to print WiFi Status info

void printWifiStatus() {
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(" dBm");
}

void quit(){
while(true);
}

@zoisdagaris it is a warning, but it appears in the Arduino IDE when you have an error, please post here a screenshot with the error and i could help you as soon as possible.

Best regards,
Metavix