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

neilh on ThingSpeak Communication Library for Arduino

$
0
0

Hi I've had an early developer edition Due+Ethernet/wiznet shield running connected to xively for a couple of years and decide to switch to thingspeak
Seems like it would be wired Ethernet shield and be transparent to the upper layer.
I tried the example first, and I wonder if anybody can shed some light on the error

Arduino: 1.6.8 (Windows 8.1), Board: "Arduino Due (Programming Port)"

WARNING: library ThingSpeak claims to run on [avr architecture(s) and may be incompatible with your current board which runs on esp8266] architecture(s).
In file included from C:\..\Documents\Arduino\libraries\ThingSpeak\examples\ReadWeatherStation\ReadWeatherStation.ino:19:0:

C:\..\Documents\Arduino\libraries\ThingSpeak\src/ThingSpeak.h:86:8: error: #error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, ESP8266, and Spark Core/Photon/Electron are supported.

#error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, ESP8266, and Spark Core/Photon/Electron are supported.

^


wheato22 on My Water Meter Reading App Communication with ThingSpeak

$
0
0

Hi Rob and RW,
Rob's Points above are on target. Water pulses arrive at a max rate of 10/minute. No need to disable interrupt handler since it takes microseconds to do the math. I'll give that a try to eliminate interactions with the Ethernet routine. Other's doing water meter apps usually count the spinning leak detector in the meter and it pulses 1000's of times per gallon. I'll eliminate off/on interrupts code and test

RW identifies my fundamental knowledge gap of Arudino programming. I have had no sure idea how to correctly merge my Water Count void loop (which works standalone) with the the Ethernet example. I understand the only one "void setup()" concept but need help on how to structure the multiple routines "void loops" on one big Sketch.

I'll try RW's "Write Voltage" example first with my specific Ethernet shield and and get that working. Then add my Water Sketch without "disabling" interrupts between pulses .

Thanks for the help.
Larry

wheato22 on My Water Meter Reading App Communication with ThingSpeak

$
0
0

Can anyone give me some assistance in getting a second Channel working. When I compile a Sketch with a second channel write i get an error for the following write instruction. (ThingSpeak.writeField(myChannelNumber,2, gallons ,myWriteAPIKey);)

"call of overloaded 'writeField(long unsigned int&, int, long unsigned int&, const char*&)' is ambiguous"

I'm thinking it's related to the fields data type but have no idea on how to fix. My Sketch follows...

Larry
***************************
// Logs flow in gallons/minute from residential water meter
#include "ThingSpeak.h"
#include
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
unsigned long myChannelNumber = 90870;
const char * myWriteAPIKey = "xxxxxxxx";
byte sensorInterrupt = 0;
byte sensorPin = 2;
volatile byte pulseCount;
unsigned long oldTime;
unsigned long gallons;
void setup()
{
Ethernet.begin(mac);
ThingSpeak.begin(client);
Serial.begin(9600);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
gallons = 0;
pulseCount = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, RISING);
}
void loop()
{
if((millis() - oldTime) > 60000)
{
oldTime = millis();
gallons = (gallons + pulseCount);
Serial.print("Pulse: ");
Serial.print(pulseCount);
Serial.print(" Gallons: ");
Serial.println(gallons);
ThingSpeak.begin (client);
ThingSpeak.writeField(myChannelNumber,1, pulseCount ,myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,2, gallons ,myWriteAPIKey);
pulseCount = 0;
}
}
void pulseCounter()
{
pulseCount++;
}

rw950431 on My Water Meter Reading App Communication with ThingSpeak

$
0
0

Try changing the type of 'gallons' to long rather than unsigned long and see if that helps

eg
long gallons;

sushma on updating multiple fields to thingspeak

$
0
0

Hans said

What does your command look like?

thank you.

the code is,

// This sketch uses a DHT11 sensor to report temperature, humidity and dew point data to http://www.thingspeak.com.
//
// Sketch tested with an Arduino Uno, a HanRun Ethernet shield and a DHT11 temperature and humidity sensor.
//
// See http://playground.arduino.cc/main/DHT11Lib for the origins of the temperature, humidity and dew point functions.

#include
#include
#include

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "99E4E2IDC9Y8J59B"; // Add your Thingspeak API key here

EthernetClient client;

// Temperature sensor settings
dht DHT;
#define DHTPIN 6

const int ONE_MINUTE = 60 * 1000;

int status;
int failedConnectionAttempCounter;

//Rounds down (via intermediary integer conversion truncation)
//See : http://lordvon64.blogspot.co.uk/2012/01/simple-arduino-double-to-string.html
String dblToString(double input, int decimalPlaces)
{
if( decimalPlaces != 0)
{
String string = String((int)(input*pow(10,decimalPlaces)));

if(abs(input) 0)
{
string = "0" + string;
}
else if(input 3 )
{
Serial.println("Re-starting the ethernet connection...");
connectToInternet();
failedConnectionAttempCounter = 0;
}
}
}

wheato22 on updating multiple fields to thingspeak

$
0
0

sushma said

hello,
actually i m using 4 fields in a channel. in that i have used first field for updating the moisture sensor data and i wann use fields 2,3,4 for updating dht11 sensor data i.e field 2 for temperature , field 3 for humidity, and field 4 for dew points. but i m not able update all the 4 fields at a time though i have multiple fields in channel setting, just the field 1 is getting updated.

---------------------
Hi,
Here is sample code from a Kickstarter project that shows a way update multiple fields with one write. It worked for me on my water meter project.
Larry

// This #include statement was automatically added by the Particle IDE.
#include "ThingSpeak.h"

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

// Sensor type
#define DHTTYPE DHT22 // DHT 22 (AM2302)

// DHT22 sensor pinout:
// Pin 1 (on the left): +3.3V
// Pin 2: output
// Pin 4 (on the right): GROUND
#define DHT_5V_PIN D1
#define DHT_SENSOR_PIN D2
#define DHT_GROUND_PIN D4

DHT dht(DHT_SENSOR_PIN, DHTTYPE);

/* Thingspeak */
TCPClient client;
unsigned long myChannelNumber = 89137;
const char * myWriteAPIKey = "3D23PQHQIJ3OZXNF";

void setup() {
// Connect to ThingSpeak
ThingSpeak.begin(client);

// Give power to the sensor
pinMode(DHT_5V_PIN, OUTPUT);
pinMode(DHT_GROUND_PIN, OUTPUT);
digitalWrite(DHT_5V_PIN, HIGH);
digitalWrite(DHT_GROUND_PIN, LOW);

// Wait for the sensor to stabilize
delay(1000);

// Initialize sensor
dht.begin();

// Read Sensor
double temperature = dht.getTempCelcius();
double humidity = dht.getHumidity();

// Update the 2 ThingSpeak fields with the new data
ThingSpeak.setField(1, (float)temperature);
ThingSpeak.setField(2, (float)humidity);

// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

// Give time for the message to reach ThingSpeak
delay(5000);

// Sleep for 15 minutes to save battery
System.sleep(SLEEP_MODE_DEEP, 15 * 60);
}

void loop() {
// This will run because the system is sleeping
}

sushma on updating multiple fields to thingspeak

sushma on updating multiple fields to thingspeak

$
0
0

i tried the code given above but it is showing compilation error at command "Adafruit_DHT/Adafruit_dht.h"


Coolio11 on Problem using Thingspeak Library with local Thingspeak installation

$
0
0

I just installed Thingspeak locally on a Raspberry Pi. The server seems to be working well, and I can successfully update my channels using python scripts.

But when using the official Thingspeak library for Arduino, I am unable to make a connection to the local server. Previously I had been using the library successfully for updating data to api.thingspeak.com.

I've tried using: ThingSpeak.begin(client,"192.168.0.178", 3000);, which contains the correct URL and port number of my local installation, but that doesn't work.

I've tried modifying the library .h file and replacing "api.thingspeak.com" with my URL, and the port 80 in the code with my local port number, but that doesn't work either.

Is there a known problem with using the Thingspeak library with a local installation? Is there a way I can get this to work? Alternatively I'll just go back to the older way of doing it, by not using the library.

Thanks!

Coolio11 on Problem using Thingspeak Library with local Thingspeak installation

$
0
0

I tried it like this too: ThingSpeak.begin(client,IPAddress(192,168,0,178), 3000); , but that didn't work either.

Then I enabled debug printing from the library, and this is the result I get (I removed the writeAPIKey):

ts::setField (field: 1 value: "0")
ts::setField (field: 2 value: "0")
ts::setField (field: 3 value: "0")
ts::setField (field: 4 value: "0")
ts::setField (field: 5 value: "0")
ts::setField (field: 6 value: "0")
ts::writeRaw (channelNumber: 3 writeAPIKey: XXXXXXXXXX postMessage: "field1=0&field2=0&field3=0&field4=0&field5=0&field6=0")
Connect to 192.168.0.178...Success.
POST "field1=0&field2=0&field3=0&field4=0&field5=0&field6=0&headers=false"
Result Code: 200

It looks like it's connecting okay, and the result code is "200" which should mean that there are no problems. But no data gets posted to the channel.

I've tried changing to a different channel with a different API key, but still it doesn't work. Everything else is working with my local installation, including reading data from multiple channels, and writing data with python. I just can't get the Arduino to post the data, with the library or without.

Coolio11 on Problem using Thingspeak Library with local Thingspeak installation

$
0
0

I finally figured it out. It only works if Rails is using Webrick, instead of the default Thin server. If I do "rails server webrick", then I'm able to upload data from the arduino, either from the official library or without the library.

Hans on Arduino uno cc3000 wifi -- data stops sending after 3-4 times

disha on thingspeak inclusion causing undesirable problems

$
0
0

I got a very basic program just reading sensor values
displayed on thingspeak with live updation w/o even requirement of
refreshing the page. Now I wanted to implement it in some other project
wherein I want to keep the source voltage at around a fixed decided
value in my case it's 14.85V-15V and I am continuously monitoring this
value and keeping same by either increasing or decreasing PWM given to
the MOSFET and then, also want to display these results of source
voltage on thingspeak.

Here is my program:

 

#include "TimerOne.h"
#include
int source_voltage = A0;
long int value_temp;
float analog(int);
float value_temp1;
int i=0,j=0;
int freq=10;
#define DEBUG FALSE //comment out to remove debug msgs

//*-- Hardware Serial
#define _baudrate 9600

//*-- Software Serial
//
#define _rxpin 0
#define _txpin 1
SoftwareSerial debug( _rxpin, _txpin ); // RX, TX

//*-- IoT Information
#define SSID "disha"
#define PASS "fiftyfive55"
#define IP "184.106.153.149" // ThingSpeak IP Address: 184.106.153.149

// GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&field2=[data 2]...;
String GET = "GET /update?key=PT41QR66HL1NH8LU";

void setup() {
pinMode(freq,OUTPUT);
pinMode(source_voltage,INPUT);
Timer1.initialize(50); // initialize timer1, and set a 1/2 second period
Timer1.pwm(10, 0);
Serial.begin( _baudrate );
debug.begin( _baudrate );

sendDebug("AT");
delay(5000);
if(Serial.find("OK"))
{
debug.println("RECEIVED: OK
Data ready to sent!");
connectWiFi();
}

}

void loop() {
char buf[16];

while(analog(source_voltage)<15) //this loop maintains source voltage at 15V
{
i--;
if(i<0)
i=1;
for(j=0;j<=10;j++)
Timer1.setPwmDuty(10,i);
value_temp1=analog(source_voltage); //source voltage calculated and stored as float value
String temp=dtostrf(value_temp1,4,1,buf); //converts float to string as thingpeak accepts only string
updateTS(temp); //this calculated value is sent for updation on channel

delay(3000);
}
i++;
if(i>1023)
i=1022;
for(j=0;j<=10;j++)
Timer1.setPwmDuty(10,i);
value_temp1=analog(pulse);
String temp=dtostrf(value_temp1,4,1,buf);
updateTS(temp);
delay(3000); //wait as thingspeak updates every 3 seconds
}
float analog(int x) //subroutine to calculate source voltage
{
int i=0;
int out;
out =analogRead(x);
float out1=(out/1023.0)*4.9;
float out2=((out1)*(21.58+98.24))/(21.58);
return(out2);
}
//----- update the Thingspeak string with 3 values
void updateTS( String T)
{
// ESP8266 Client
String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
delay(2000);
if( Serial.find( "Error" ) )
{
debug.print( "RECEIVED: Error
Exit1" );
return;
}

 cmd = GET + "&field1=" + T +"
";
Serial.print( "AT+CIPSEND=" );
Serial.println( cmd.length() );
if(Serial.find( ">" ) )
{
debug.print(">");
debug.print(cmd);
Serial.print(cmd);
}
else
{
sendDebug( "AT+CIPCLOSE" );//close TCP connection
}
if( Serial.find("OK") )
{
debug.println( "RECEIVED: OK" );
}
else
{
debug.println( "RECEIVED: Error
Exit2" );
}
}

void sendDebug(String cmd)
{
debug.print("SEND: ");
debug.println(cmd);
Serial.println(cmd);
}

boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP
delay(2000);
//Connect to Router with AT+CWJAP="SSID","Password";
// Check if connected with AT+CWJAP?
String cmd="AT+CWJAP=\""; // Join accespoint
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
sendDebug(cmd);
delay(5000);
if(Serial.find("OK"))
{
debug.println("RECEIVED: OK");
return true;
}
else
{
debug.println("RECEIVED: Error");
return false;
}

cmd = "AT+CIPMUX=0";// Set Single connection
sendDebug( cmd );
if( Serial.find( "Error") )
{
debug.print( "RECEIVED: Error" );
return false;
}
}

Now in void loop you can see that there is a loop which always maintains the source voltage fixed at around 14.85 or 15V and the same is updated using function :::::----> updateTS(temp);

Here some contradictory results I have got that is:

1)When I just wanted to check source voltage whether remained at desire value w/o bothering for utilizing thingspeak evreything worked fine.

2)But in void loop when I included that function

updateTS(temp); The source voltage sat at open circuit voltage and the same values got displayed and when i commented that function and very next line i.e delay(3000); everything again worked. Those two code lines are very important for updating on thingspeak what do you'll think? Why is this happening? How can I solve this?

froggy2288 on Trouble with DUE

$
0
0

I cannot get any code for my DUE to compile if I include ThingSpeak.h, get the following error:

#error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, ESP8266, and Spark Core/Photon/Electron are supported.

My setup is a DUE with the Adafruit CC3000 breakout. The code is literally just the adafruit CC3000 example with "#include <ThingSpeak.h>" at the top. If I remove that library include then the wifi example code works great and connect to my network and successfully pings adafruit.com. 

I have used IDE 1.6.6 and 1.6.8.

Any advice would be greatly appreciated.

rw950431 on thingspeak inclusion causing undesirable problems

$
0
0

Note that Thingspeak updates can be no more often than 15 seconds so you need to choose a different service if you want 5 second updates.

Adding the call to updateTS() and the delay() adds at least 5 seconds to every iteration of the inner loop so by the time you do this 10 times almost a minute has passed before you can change the voltage at all.

Why do you call setPwmDuty() 10 times with the same value?  Seems pointless.. the value you set remains active on the pin until you change it.

I would try something like

v=analog(source_voltage)

if (v<14.85) {

  if (i<1022) i++;

}

if (v>15.0) {

  if (i>0) i--;

}

Timer1.setPwmDuty(10,i)

updateTS() // etc

 

So at least you can respond every 5 seconds or so.

 

If the load is likely to change more rapidly than this it will make it very hard to control it and make regular updates to Thingspeak


sinet666 on Talkback // How to make an LED blink when Thingspeak Data Exceeds A Particular Value

$
0
0

Hi,

I can successfully upload data using Arduino, ESP8266 and Thingspeak.

 

Now i need your help on how i can control my Arduino, example; blink an LED using Thingspeak Talkback.

Another example would be, Lets say i want to turn any device on or off using internet only, ie, if someone is not near the Arduino, to which all components are connected, and he/she wishes to control my devices using the thingspeak and the internet.

Any suggestions would be deeply appreciated. Thank you.

Regards,
K. Raghavendran

rw950431 on Talkback // How to make an LED blink when Thingspeak Data Exceeds A Particular Value

$
0
0

Have you looked at the section off the thingspeak documentation call "update a channel and Execute the next talkback command"?

Your program needs to read through the response it gets from Thingspeak and look for the text set by the talkback.  There is some example code at http://bildr.org/2011/06/arduino-ethernet-client/ but you may have to adapt it to ESP8266

mdahlb on Read last value AND time/date from thingspeak

$
0
0

Hello,

I'm trying to read the last value AND the date/time from a private channel to my Arduino. I can easily get the last value using the "official thingspeak library for arduino" and the "ReadPrivateChannel"-example. But what about the timestamp (date/time) for that last value? It's not a part of the Thingspeak library I think..

I can access the last value and the timestamp by a get request and get a return in JSON format (this is my privat channel...):

https://api.thingspeak.com/channels/106334/fields/1/last.json?key=J38Y445RB2G9FNL0&timezone=Europe%2FStockholm

 

How do I make my Arduino to "read" this url? I been trying to make a GET request but without any success... =(

 

Regards

Mattias

mdahlb on How to send sensor data to thingspeak using SIM 900 for internet connection

rw950431 on Read last value AND time/date from thingspeak

$
0
0

Maybe you have to use readRaw() and parse the string yourself?

 From https://github.com/mathworks/thingspeak-arduino/blob/master/src/ThingSpeak.h

/**
* @brief Read a raw response from a public ThingSpeak channel
* @param channelNumber Channel number
* @param URLSuffix Raw URL to write to ThingSpeak as a String. See the documentation at https://thingspeak.com/docs/channels#get_feed
* @return Response if successful, or empty string. Use getLastReadStatus() to get more specific information.
* @remark This is low level functionality that will not be required by most users.
* @code
void loop() {
String response = ThingSpeak.readRaw(myChannelNumber, String("feeds/days=1"));
Serial.print("Response: ");
Serial.print(response);
delay(30000);
}
* @endcode
*/
Viewing all 172 articles
Browse latest View live