Quantcast
Channel: ThingSpeak IoT Community - Forum: Arduino
Viewing all 172 articles
Browse latest View live

irproject on Send data from ThingSpeak to ESP8266

$
0
0

Hi

I succeeded send data from a sensor (by Arduino Uno + esp8266) to my ThingSpeak channel.

Now I want to send back data from my channel to Arduino Uno.

Help?  tnx


loli72 on Need help posting data using RN171 wifi shield and wifly library

$
0
0

Hello, could you please post your entire code. At least the code to connect this wifi schield to Thingspeak as a client. I manage to connect whit a ethernet schield but I'm lost with this one.

ICar on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

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");
}

rw950431 on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Does startGSM() claim to succeed?  - Do you get the "connected" message printed out..

Perhaps you can try calling Thingspeak.begin()  only after you connect to GSM rather than before?

If that doesnt work you can avoid the thingspeak library altogether and just construct the URL yourself (its possible that the thingspeak library isnt tested for GSM since the source only refers to WiFi and Ethernet)

Sample code for a web client is https://www.arduino.cc/en/Tutorial/GSMExamplesWebClient

The URL you need can be found on the "Data Import/Export" tab of your channel page on the thingspeak website.

ICar on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Thang you for your tip. Yes the startGSM() works fine and I get the Massage connected. I try your idea to change the position of Thingspeak.begin() after the startGSM() but the code still stops working after uploading the two values, like bevor. I think your right I should avoid the ThingSpeak.h library. I already working on come code for that. Down below is my code. With this code I am able to upload one value to feld1 on ThingSpeak but not two values. It looks easier than it is. When I call the function updateThingSpeak("field1="+analogValue) again for the fild2 I get a Bad request error.

Any ideas?

//------------------------------------Bibliotheken--------------------------------------------------------------------------------------------------------------           
#include <SPI.h>                           
#include <GSM.h>
//------------------------------------Definitionen für SIM-Karte------------------------------------------------------------------------------------------------           
#define PINNUMBER "XXX"                   
#define GPRS_APN "internet.t-mobile"
#define GPRS_LOGIN "t-mobile"
#define GPRS_PASSWORD "XX"

//------------------------------------Variablen für SIM-Karte---------------------------------------------------------------------------------------------------           
GSMClient client;
GPRS gprs;
GSM gsmAccess;

uint16_t reset = 0;     
int Wert1 = 0;                          //Startwert auf 0 gesetzt
int WEert1_alt;
boolean neuWert = true;

long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
//------------------------------------Variablen für Datencloud--------------------------------------------------------------------------------------------------         

char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "XXX";
const int updateThingSpeakInterval = 16 * 1000;

void setup() {

  Serial.begin(9600);                  // Initialiesiere Serial port (Baudrate:9600)                         
  pinMode(9, OUTPUT);
  pinMode(2, INPUT);
  startGSM();
 
}

void loop() {
 
  String analogValue = String(Wert1, DEC);   
 
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
   
  }
 
  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected)
  {
    Serial.print(Wert1);
    Serial.println("...disconnected");
    Serial.println();
    client.stop();
    neuWert = false;
  }
 
  // Update ThingSpeak
  if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval) && neuWert == true && Wert1 > 0)
  {
    updateThingSpeak("field1="+analogValue);
  }
 
  // Check if Arduino Ethernet needs to be restarted
  if (failedCounter > 3 )
  {
    startGSM();
    }
 
  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");
}

void updateThingSpeak(String tsData)
{
  if (client.connect(thingSpeakAddress, 80))
  {         
    client.print("POST /update HTTP/1.1
");
    client.print("Host: api.thingspeak.com
");
    client.print("Connection: close
");
    client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"
");
    client.print("Content-Type: application/x-www-form-urlencoded
");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("

");

    client.print(tsData);
   
    lastConnectionTime = millis();
   
    if (client.connected())
    {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
      failedCounter = 0;
    }
    else
    {
      failedCounter++;
      Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");   
      Serial.println();
    }
  }
  else
  {
    failedCounter++;
    Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");   
    Serial.println();
    lastConnectionTime = millis();
  }
}

piajola on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Hi ICar,

You say

int Wert1 = 0; //Startwert auf 0 gesetzt

google helped me saying you say start with value=0
but you never made it greater than 0
and you check

if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval) && neuWert == true && Wert1 > 0){

to run your routine void updateThingSpeak(String tsData) that will never run

 

Also you can do (semi pseudo-code)

analogValue = "field1=" + str(Wert1) + "field2=" + str(Wert2)
...
...
updateThingSpeak(analogValue);

 

Hope this is some helpWink

Good luck (&& | ask again)

ICar on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Hi piajola,

You are absolutely right with the “int Wert1=0”. That was a volatile mistake from me.

I am still working on the problem to upload two variables to ThingSpeak. The code example you give me (analogValue = "field1=" + str(Wert1) + "field2=" + str(Wert2) )looks good but how is the right implementation for that. I try a lot variation of that but still no idea. What did you mean with str?

Thank you very much for your help.

piajola on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Hi ICar,

str is "string" the idea is concatenate one string from 2 strings plus 2 numbers. (convert the number to string)

It depends in the "type" of number int, float, etc.

My particular case is I have 2 numbers from my sensor

      float valHumidity;
      float valTemperature;

and thingspeak wants to receive one string that my "internet device" must compose. So my string is

    altSer.print(F("GET /update?api_key=")); // 20 chars
    altSer.print(apiKey);                            // 16 chars
    altSer.print(F("&field1="));                   // 8 chars
    altSer.print(String(valTemperature));      // 5 chars
    altSer.print(F("&field2="));                   // 8 chars
    altSer.print(String(valHumidity));            // 5 chars
    altSer.print(F("

"));                    // 4 chars

because also I must say how many characters I am sending. Capital F so arduino put the fixed strings in flash and use less RAM

      "&field1="+String(valTemperature))+"&field2="+String(valHumidity))

is the same string, but as I did is cleaner to see 2 years after to repeat

My device get the string and do whatever needed to send "really to Internet"

I do not know how to use your device but I think it is "more or less" the same thing

 

Hope still making sense Wink


ICar on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Hi piajola,

Thank you very much for your help. It works now! Great idea to put both variables in one string. The solution is:

   String analogValue = String(Wert1, DEC);

   String analogValue2 = String(Wert2, DEC); 

senden="&field1="+analogValue+"&field2="+ analogValue2; 

and after this you can just call the “updateThingSpeak(senden);” function.

I am really happy now. Thank you again and great job.

piajola on Upload two values to ThingSpeak with a Arduino GSM Module?

$
0
0

Hi ICar,

Glad to know your status ... Cool

Welcome to the exclusive club of Iot(ers) I hope for a long membership

And help someone you know you can help

Smile

salim on 1440 Averaging Inaccuracy

$
0
0

I am new to the ThingSpeak platform and I am trying to display the 1440 average of my data I am sending from an Arduino Uno. I am sending data from 5 different detectors to be plotted into 5 different fields on my ThingSpeak channel. The live data plotted is quite accurate but when I chose to plot the average I get values significantly lower than it should be. I am suspecting it to have something to do with the bunch of Null values I have here for example maybe: https://thingspeak.com/channels/126439/field/4.json

Hans on 1440 Averaging Inaccuracy

$
0
0

You are correct. The average is using null's and lowering the expected average.

If you have two devices, you might want to update two different ThingSpeak channels.

If that is not possible, then MATLAB can help here. You can use MATLAB Analysis app to read in the field data, ignore the nulls, and then calculate the average. You can even use MATLAB to write the averaged data to a new processed channel and have it calculate the daily average each day by scheduling it with TimeControl.

Tonibco6 on Dragino-KPN-ThingSpeak

$
0
0

Hi all,

I am actually developing an IOT project based on LoRa module. To be specific, I am using Dragino device to send temperature-Humidity data from sensors.

The point is that I am sensing this data to KPN provider, which is a Dutch Network, and finally my goal would be transfer this data from KPN to ThingSpeak platform to monitorise them.

My question is, once I have got KPN ABP Keys as well as I have been testing that I am able to upload data to KPN, then Which API links should I use to match KPN Network with ThingSpeak platform. KPN Support did request me for a link in order  to send my data to ThingSpeak platform, but I have just sent them my public channel link and it didn't work.

I have actually got a simple Arduino client/server Sketches which manage to connect my Dragino Module with ThingSpeak platform throughout a private Network (gateway). However, my actual target is send this data from KPN Network to ThingSpeak instead.

Any help/suggestion, please?

Many thanks

dtecres on Arduino Uno R3+W5100+LM35, Temperature not display in Thingspeak...

$
0
0

Dear All,

I'm trying to use the W5100 Ethernet Shield with Arduino Uno R3 to send the temperature read from LM35 to Thingspeak. 

Unfortunately, nothing happened after an hour (interval is 5 minutes). I can't find any wrong in the code and I don't know what went wrong. Frown 

I'm attaching the code as below:

#include <SPI.h>
#include <Ethernet.h>
#include "ThingSpeak.h"

// W5100 Network Setup
byte W5100_MacAddress[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

//Thingspeak Setup
unsigned long Channel_Number = 302633; // Channel ID
const char * Write_API_Key = "VAMPTX0YTHJ17WJ5"; // Write API Key
int Channel_Field = 1; // Field where Temperature data upload to

// LM35 sensor input to analog
#define LM35_Temp_Sensor A0

EthernetClient client;

float LM35_Temp_Value = 0; // Initial Temperature value
int Interval = 300; // Interval read the temperature every 5 mins

void setup()
{
// Serial connection
Serial.begin(9600);

// Disable SD Card SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

// Connect to local network and internet
Ethernet.begin(W5100_MacAddress);
Serial.println();
Serial.print("W5100 IP Address: ");
Serial.println(Ethernet.localIP());
Serial.print("W5100 Subnet Mask: ");
Serial.println(Ethernet.subnetMask());
Serial.print("W5100 Gateway: ");
Serial.println(Ethernet.gatewayIP());
Serial.println();

// Connect to Thingspeak server
if (ThingSpeak.begin(client))
{
Serial.println();
Serial.println("Connect to Thingspeak Server...");
Serial.println();
}
else
{
Serial.println();
Serial.println("Failed to connect to Thingspeak Server!!!");
Serial.println();
}

}

void loop()
{
LM35_Temp_Value = analogRead(LM35_Temp_Sensor)* 0.0048828125 * 100;
Serial.print("Current temperature: ");
Serial.print(LM35_Temp_Value);
Serial.println("°C");
delay(100);

// Write the temperature to Thingspeak Server
if(ThingSpeak.writeField(Channel_Number, Channel_Field, LM35_Temp_Value, Write_API_Key))
{
Serial.println();
Serial.println("Uploading data to Thingspeak Server...");
Serial.println();
}
else
{
Serial.println();
Serial.println("Failed to upload data to Thingspeak Server!!!");
Serial.println();
}

// The temperature will read every 5 mins
for (int i=0; i <= Interval; i++)
{
delay(1000); // 1 second delay
}

}

rushanarshad on Dispalying Sum in Thingspeak Channel

$
0
0

Hello guys,

 

I must appreciate Thingspeak is a very good platform. However, I am stuck at one thing and need help from the community. I am using hall-effect sensor to send liquid data from arduino to my channel through wifi. The liquid is usually in 100s of ml. I want to display the liquid for some specific hours, days and weeks and even months. But I am unable to see that in my graphs. 

Channel link is: https://thingspeak.com/channels/302158. I am using 20s delay to send the data and I only have one field in my channel. 

Can anyone help me in this? It would be much appreciated.

Best Regards

Rushan


rushanarshad on Cant send Unsigned long values from arduino to ThingSpeak

$
0
0

Hello guys,

I am trying to send my liquid sensor data to ThingSpeak. But, my total liquid variable is unsigned long. The following error comes up in compiling: 

no matching function for call to 'ThingSpeakClass::writeFields(long unsigned int&, int, long unsigned int&, const char*&)'

What could be the reason for this? 

Best Regards

Rushan

cstapels on Arduino Uno R3+W5100+LM35, Temperature not display in Thingspeak...

$
0
0

What response are you getting from the server?

try 

int response =thingSpeak.writeFireld(...;

serial.println("Response from server "+ String(response));

and see what the response says.

dtecres on Arduino Uno R3+W5100+LM35, Temperature not display in Thingspeak...

$
0
0

Hi Cstapels,

I get the response as below:

Response from server -302

Thanks. Smile

cstapels on Arduino Uno R3+W5100+LM35, Temperature not display in Thingspeak...

$
0
0

302 is a redirection, I don't thing thingSpeak would provide that to you directly.  A wild guess is that your network is redirecting the request away from ThingSpeak.  Are you able to update the channel from a browser or GET using POSTMAN connected on the same network?  You can use the syntax below, which is shown here in the documentation.

https://api.thingspeak.com/update?api_key=<your Write API KEY>&field1=1010 

 

Are you able to update the channel this way?

Tonibco6 on Dragino-KPN-ThingSpeak

$
0
0

I have finally managed to get the right code to send my dht_11 data to KPN network from LoRa (Dragino) node. However, my next step consists on transmit this data to ThingSpeak platform throughout KPN network.

https://zakelijkforum.kpn.com/lora-forum-16/what-is-lora-and-lorawan-8314

So, basically the target consists in sending this data from LoRa node to KPN network, and then, forward it to ThingSpeak.
So that, I am actually adding into the sketch the chance to send this data to ThingSpeak, nevertheless, no data is showed on ThingSpeak dashboard.
The link below is pointed to my new code. I added the functions and variables I thought were the proper ones, however, I didn't manage to send it. May I get some support or correction to achieve it, please?

Sketch link: https://github.com/Tonibco/Dragino-KPN-Project/blob/master/Dragino_KPN.ino

Many thanks

Toni

Viewing all 172 articles
Browse latest View live