[SOLVED] Need to send value to ubidots from 4G+GPS Shield


Dear All,
I have 4G shield and connected to Arduino Mega board.

4G+GPS Shield board:

4G+GPS shield POST example code:

Able to run the HTTP POST/GET examples and working without any problem.
Now I want to send values to Ubidots server, I’ve given the Ubidots server and Token values etc., but I’m getting server response as 403.

If we have arduino board + Ethernet shield, here is the example how we can send the value to ubidots, like HTTP URL formation, but this 4Garduino library doesn’t support “client.println” APIs.

In same way, how we can form URL for 4G shield, our example looks like this.

I need to push the value 10 to the variable ID.

char host[] = “things.ubidots.com”;
uint16_t port = 80;
char resource[] = “/api/v1.6/variables/58379c7376543216eea6a485/values”;
char data[] =“token=cRsjMrUvtRFYABCDEyRLkSsyg7oHCh” ;
//don’t know how to send this value in JSON format --> “{“value”:10}”;

Using above, I’m getting 403 HTTP error ID.

The below settings worked for me for POST URL:
char host[] = “mockbin.org”;
uint16_t port = 80;
char resource[] = “/bin/bbe7f656-12d6-4877-9fa8-5cd61f9522a9”;
char data[] = “foo=bar&foo=baz”;

Can you please help me on this problem ?

Titus S.


Hello, according to Libelium developers this shield doesn’t support JSON objects:


Actually Ubidots doesn’t support this board with some library but you may post your values in other way, directly in the url, for this please construct the next url format and post it:


Simply replace your TOKEN and your variable id (this last one can be found on the left side of the variable where you will store your value).


If you post something like this:


you’ll save a value of ‘2’ to the variable with ID 432628f87625427cae440b7a.

I think that you can construct the url with something like this, but I cannot probe it because we don’t have that shield here:

char host[] = “translate.ubidots.com”;
uint16_t port = 80;
char resource[] = “/api/postvalue”;
char data[] = “token={TOKEN}&variable={VARIABLE_ID}&value={VALUE}”;

Hope it works, you can ask too for help on libelium forum post in order to know how to build properly the url:



Thank you so much for your reply Jotathebest.
I’ve got “HTTP code 201” i.e unauthorized.

What could be the problem ?

Can you please help me on this issue ?

Titus S.


Hello, please use GET instead POST when you construct the request. You can guide from the example at the end of this post:



Hi Again,
Thanks for your reply.
I’ve tried it, but I’ve got error this time.
Seems, we can use POST.

This is the forum link that we have posted, not getting replies :frowning:

Can you please help me on this ?


Hello titusece, if you use the url type: http://translate.ubidots.com/api/postvalue?token=TOKEN&variable=VARIABLE_ID&value=2 you need to make a GET request and not a POST, if you wanna use a POST HTTP request you need to build a JSON dictionary that as I have read is not possible with your board.

Actually we don’t have any library for your board so any previous test have been made, I saw in the post of cooking-hacks that you have had some replies, have you tried them? In that post they constructed a socket with a JSON so it should work if the board sends it properly.


Thank you. Its working now.
Thank you very much. I appreciate your kind help.
I want to send two values to ubidots (longitude and latitude)
Can you please tell me how can I send two variables in single url ?
Also any documentation for maps widget ?
How can I see the location in maps widget using my two values of longitude and latitude ?


Hello Titusece, I’m glad to listen that you made it work, Would you share with us your code please for future references and for trying to guide you?

If you need to send multiple values, you can construct this url:


For widgets documentation, please refer to our youtube channel:


For sending the context please construct this url:




Thanks, now I’m able to send the long/lang GPS location to ubidots.
Thanks for your help.

Here is the complete code snippet for others.

    -------------------------- 4G_06 - HTTP GET  ------------------------- 
    Explanation: This example shows how to send HTTP GET requests

    Note 1: in Arduino UNO the same UART is used for user debug interface 
    and LE910 AT commands. Handle with care, user interface messages could 
    interfere with AT commands.

    It is seen as wrong AT command by the LE910 module.

    Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Version:           1.1
    Design:            David Gascon
    Implementation:    Alejandro Gallego, Yuri Carmona, Luis Miguel Marti
    Port to Arduino:   Ruben Martin

#include "arduino4G.h"

// APN settings
char apn[] = "DST.internet";
char login[] = "";
char password[] = "";

// SERVER settings
char host[] = "translate.ubidots.com";
uint16_t port = 80;
char resource[100];
char resource2[100];

// variables
uint8_t error;
float longi = 1.56;
float langi = 2.56;
int test = 100;
char str_temp[16];
char str_temp2[16];

uint8_t gps_status;
float gps_latitude = 2.3456;
float gps_longitude = 1.2345;
uint32_t previous;
bool gps_autonomous_needed = true;

void setup()
  error = _4G.ON();
  Serial.println(F("Start program"));

  // GET method to the Libelium's test url                              
  // You can use this php to test the HTTP connection of the module.    
  // The php returns the parameters the user sends with the URL.        

  // 1. sets operator parameters
  _4G.set_APN(apn, login, password);

  // 2. Show APN settings via USB port

void loop()
  // 1. Switch ON
  error = _4G.ON();

  if (error == 0)
    Serial.println(F("1. 4G module ready..."));

    // 2. HTTP GET gps_latitude
    Serial.println(F("2. Getting URL with GET method..."));

    dtostrf(gps_latitude, 4, 2, str_temp);
    dtostrf(gps_longitude, 4, 2, str_temp2);


    // send the request
    error = _4G.http( GET_METHOD, host, port, resource);

    // Check the answer
    if (error == 0)
      Serial.print(F("Done. HTTP code: "));
      Serial.print("Server response: ");
      Serial.println((char *)_4G._buffer);
      Serial.print(F("Failed. Error code: "));
      Serial.println(error, DEC);
    // Problem with the communication with the 4G module
    Serial.println(F("1. 4G module not started"));
    Serial.print(F("Error code: "));
    Serial.println(error, DEC);

  // 3. Powers off the 4G module
  Serial.println(F("3. Switch OFF 4G module"));

  // 4. Sleep


please tell me the hardware you used.



This is the board I used to test.