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”;
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:
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 ?
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.
Example:
Serial.print("operATo");
It is seen as wrong AT command by the LE910 module.
Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
http://www.libelium.com
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
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
///////////////////////////////////////
//http://translate.ubidots.com/api/postvalue?token=cRsjMrABCDFYTZFRGyRLkSsyg7oHCh&variable=58379cabc6254256eea6a485&value=2.2
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
//////////////////////////////////////////////////
_4G.show_APN();
}
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);
sprintf(resource,"/api/postvalue?token=cRsjMrUvtRFABCFRGyRLkSsyg7oHCh&variable=58466bf0762512345b08b60f&value=%d&context=lat=%s,lng=%s",test,str_temp,str_temp2);
Serial.println(resource);
// send the request
error = _4G.http( GET_METHOD, host, port, resource);
// Check the answer
if (error == 0)
{
Serial.print(F("Done. HTTP code: "));
Serial.println(_4G._httpCode);
Serial.print("Server response: ");
Serial.println((char *)_4G._buffer);
}
else
{
Serial.print(F("Failed. Error code: "));
Serial.println(error, DEC);
}
}
else
{
// 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"));
_4G.OFF();
////////////////////////////////////////////////
// 4. Sleep
////////////////////////////////////////////////
delay(10000);
}