Halo everyone,
I want to upload 2 values to ThingSpeak in feld1 and feld2. I use an Arduino uno and a GSM module for that. I have already work out some code that work but not as good as I want. I am working with the ThingSpeak.h but I don’t think the library good for the use with the GSM Module. The problem with the code below is that die code stops working after the two values are sended to ThingSpeak. So the loop function just stop there. I don’t know why. Even when after the function writeFields() some more function came. The getLastReadStatus () doesn’t work also. Do you have any idea how to fix this problem? The loop function and the values should send some values over and over again.
Or do you know other methods to upload more very values to ThingSpeak with the GSM module from Arduino?
thank you in advance.
//------------------------------------Bibliotheken--------------------------------------------------------------------------------------------------------------
#include <SPI.h>
#include <GSM.h>
#include "ThingSpeak.h"
//------------------------------------Definitionen für SIM-Karte------------------------------------------------------------------------------------------------
#define PINNUMBER "XXX"
#define GPRS_APN "internet.t-mobile"
#define GPRS_LOGIN "t-mobile"
#define GPRS_PASSWORD "XXX"
//------------------------------------Variablen für SIM-Karte---------------------------------------------------------------------------------------------------
GSMClient client;
GPRS gprs;
GSM gsmAccess;
uint16_t reset = 0;
int Wert1 = 80; /
int Wertalt;
boolean neuerWert = true;
int Wert2 =5;
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
//------------------------------------Variablen für Datencloud--------------------------------------------------------------------------------------------------
const char * myWriteAPIKey = "XXX";
unsigned long myChannelNumber = 000;
//Zählervariablen für neunstart
int seconds =0;
//CanAktiv erkennen
boolean CANschlaf=false;
boolean GSMaus=true;
void setup() {
Serial.begin(9600); // Initialiesiere Serial port (Baudrate:9600)
ThingSpeak.begin(client);
pinMode(5, INPUT); //die Pins 9,6 und 3 sind durch die ThingSpeak lib schon beleckt und werden zum ansteuern einer RGB genutzt. Solten nicht verwendet werden.
digitalWrite(5,HIGH);
pinMode(2, INPUT);
CANschlaf=digitalRead(5);
startGSM();
GSMaus=false;
}
void loop() {
// Update ThingSpeak
if(neuerWert== true && Wert1 > 0)
{
if(GSMaus==true)
{
startGSM();
GSMaus=false;
}
ThingSpeak.setField(1,Wert1);
ThingSpeak.setField(2,Wert2);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
int resultCode = ThingSpeak.getLastReadStatus();
if(resultCode == 200)
{
Serial.print("OK");
}
else
{
Serial.print("Error reading message. Status was: ");
Serial.println(resultCode);
}
neuerWert == false;
delay(15000);
Wert1--;
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 )
{
startGSM();
GSMaus=false;
}
lastConnected = client.connected();
}
void startGSM() {
boolean notConnected = true;
Serial.println("try to connect to GSM...");
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("Connected");
}