Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Arduino Logger GSM API Not connecting

Tags: #<Tag:0x00007f1bd80e3d50> #<Tag:0x00007f1bd80e3c88>

I’m using an arduino uno to monitor the environment (temp, humidity, pressure etc). I want to send the data collected on the device to my emoncsm account using a GSM shield. The device I’m using can’t use wifi or ethernet (most arduino projects I’ve seen are specific to these) and so I need a GSM solution.

I’ve managed to use the GSM shield to perform the default WebClient function, but when I change the information in the code to match the emoncms information, the device will not connect. I’ve tried all kinds of variations without any luck. If anybody could help with this, that would be great.

The serial monitor suggests the device connects to data, but cannot connect to emoncms.

The code I’ve used so far:

#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// APN data
#define GPRS_APN       "mobiledata" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password
// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// URL, path & port (for example: arduino.cc)
char server[] = "emoncms.org";
int port = 80; // port 80 is the default for HTTP
void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;
  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (notConnected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  Serial.println("connecting...");
  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print("/input/post?json={power:200}&apikey=b1963xxxaefbdxxxxcb0627xxx2b0011");
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}
void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing forevermore:
    for (;; )
     
  }
}