Hello everyone,
I tried to work this out myself but I am stuck. I am using an Arduino Uno with the latest version of the official Arduino GSM shield. I hooked up a DHT22 temp/humidity sensor and I want to stream data using phant.
I have used the same setup with the ethernet shield and it works with no problems. But now with GSM shield it connects to the APN fine but when posting data to my sparkfun stream I get NAN values. Also the code get stuck when displaying the server response.
Here is what the serial monitor spits out:
conntecting to APN
APN connected
conntecting to Server
Server connected
Posting!
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,DELETE
Access-Control-Allow-Headers: X-Requested-With, Phant-Private-Key
Content-Type: text/plain
X-Rate-Limit-Limit: 300
X-Rate-Limit-Remaining: 299
X-Rate-Limit-Reset: 1442755674.359
Date: Sun, 20 Sep 2015 13:12:54 GMT
Set-Cookie: SERVERID=phantworker2; path=/
Cache-Control: private
Conne
And that’s where it finishes…
My Arduino code:
/*
LowPower library by rocketscream.com
*/
#include <GSM.h> // Importing all appropriate libraries
#include <HttpClient.h>
#include "DHT.h"
#include <LowPower.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define PINNUMBER "" // SIM PIN
#define GPRS_APN "internet.t-mobile" // replace with your GPRS APN
#define GPRS_LOGIN "t-mobile" // replace with your GPRS login
#define GPRS_PASSWORD "tm" // replace with your GPRS password
GSMClient client;
GPRS gprs;
GSM gsmAccess;
/////////////////
// Phant Stuff //
/////////////////
IPAddress server(54,86,132,254);
const String publicKey = "0lLR6nnpVwhljmr4lGNa";
const String privateKey = "D6xZVkkjovublmn9bGqw";
const byte NUM_FIELDS = 2;
const String fieldNames[NUM_FIELDS] = {"temp", "humidity"};
String fieldData[NUM_FIELDS];
boolean notConnected = true;
int wait = 0;
int redLed = 10; // Red LED pin
int greenLed = 8; // Green LED pin
float temp = 0;
float humid = 0;
void setup(void) {
Serial.begin(115200);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
digitalWrite(redLed, HIGH); // Red LED while not connected
digitalWrite(greenLed, LOW);
}
void loop(void) {
if(wait>=1){ // If slept 25 times
startConnection();
temp+=dht.readTemperature();
humid+=dht.readHumidity();
fieldData[0] = String(temp);
fieldData[1] = String(humid);
Serial.println("Posting!");
postData();
delay(5000);
closeConnection();
wait=0; // Reset sleep-counter
}
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); // Enter power down state for 8 s with ADC and BOD module disabled
wait++;
}
void startConnection(){
while (notConnected) {
digitalWrite(3,HIGH); // Enable the RX pin
Serial.println("conntecting to APN");
if(gsmAccess.begin(PINNUMBER)==GSM_READY){
delay(3000);
if(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY){
notConnected = false;
Serial.println("APN connected");
digitalWrite(redLed, LOW); // Green LED when connected
digitalWrite(greenLed, HIGH);
// if you get a connection, report back via serial:
Serial.println("conntecting to Server");
if (client.connect(server, 80))
{
Serial.println("Server connected");
}
else
{
// if you didn't get a connection to the server:
Serial.println("Server connection failed");
}
}
}
else{
digitalWrite(redLed, HIGH); // Red led to indicate some possible problems
Serial.println("APN NOT connected");
delay(1000);
}
}
}
void closeConnection(){
while(notConnected==false){
if(gsmAccess.shutdown()){
delay(1000);
digitalWrite(3,LOW); // Disable the RX pin
notConnected = true;
Serial.println("not connected");
digitalWrite(redLed, LOW); // Turn LEDs off
digitalWrite(greenLed, LOW);
}
else{
delay(1000);
}
}
}
void postData()
{
// Make a TCP connection to remote host
if (client.connected())
{
// Post the data! Request should look a little something like:
// GET /input/publicKey?private_key=privateKey&light=1024&switch=0&name=Jim HTTP/1.1\n
// Host: data.sparkfun.com\n
// Connection: close\n
// \n
client.print("GET /input/");
client.print(publicKey);
client.print("?private_key=");
client.print(privateKey);
for (int i=0; i<NUM_FIELDS; i++)
{
client.print("&");
client.print(fieldNames[i]);
client.print("=");
client.print(fieldData[i]);
}
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
else
{
Serial.println(F("Connection failed"));
}
// Check for a response from the server, and route it
// out the serial port.
while (client.connected())
{
if ( client.available() )
{
char c = client.read();
Serial.print(c);
}
}
Serial.println();
client.stop();
}
Any Ideas? I’d be super happy if someone can help!