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

mdahlb on ThingSpeak Communication Library for Arduino

$
0
0

Hello,

Is there a simple way to read the last value AND the timestamp for that value? I can easily read the last value, thanks to the library, but what about the time and date? 

↧

mdahlb on Read last value AND time/date from thingspeak

$
0
0

Thanks!

Well, I managed to get the "age" (in seconds) of the most recent entry by adding the following code:

String response = ThingSpeak.readRaw(myChannelNumber, String(String("/fields/") + String(1) + String("/last_data_age")), myReadAPIKey);
Serial.print("Response: ");
Serial.print(response);

 

So, I get the age in seconds although then I have to convert it into a date and time. Hmm, I would be more convinient if I just could get the time/date at once..

↧
↧

dukeofboz on thingspeak and 1sheeld Arduino shield

$
0
0

hi there,

I have tried to use the Arduino 1sheeld (www.1sheeld.com) to send sensor data to my fields in my thingspeak private channel. That worked fine.

Now I'm trying to do the opposit: Getting data from field1,field2,field3 from my private thingspeak channel to trigger 3 LEDs.

Does the thingspeak library work with 1sheeld? If not, what should the script in Arduino be without the library used?

↧

sheahudson on No Data Transfered to Thingspeak

$
0
0

Hello, can anyone help me. I am new in learning about ThingSpeak and Arduino. I want to make send data from LM35 that connected to Arduino to ThingSpeak using Ethernet Shield. The program can be run but ThingSpeak does not update any of the data receive. How do I fixed this? This is the sample code that I have try.

Thank You

 

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

int val;
int tempPin = 0;
float tempC;

// Local Network Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF }; // Must be unique on local network

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "24AU1NCYHNIXFYEN";

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;

// Initialize Arduino Ethernet Client
EthernetClient client;

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

// Start Ethernet on Arduino
startEthernet();

}

void loop()

{
int val = 0;
for(int i = 0; i < 10; i++)
{

val += analogRead(tempPin);
delay(200);

}
float tempC = val*50.0f/1023.0f;
char buf[16];

// Read value from Input Pin
String LM35 = dtostrf(tempC,4,1,buf);

Serial.println(LM35);

// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println("...disconnected");
Serial.println();

client.stop();
}

// Update ThingSpeak
if (!client.connected())
{
updateThingSpeak(LM35);
delay(25000);
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {
startEthernet();
}

lastConnected = client.connected();
}

//----- update the Thingspeak string with 1 value
void updateThingSpeak(String M)
{
if (client.connect(thingSpeakAddress, 80))
{
String cmd = writeAPIKey +"&field1=" + M;
Serial.println("Connecting to ThingSpeak...");
Serial.println("Sending Data");
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(cmd.length());
client.print("

");

client.print(cmd);
Serial.println(F("Done"));
Serial.println(F("Waiting 30 sec for next sending"));

lastConnectionTime = millis();

if (client.connected())
{
failedCounter = 0;
client.stop();
}
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();
}
}

void startEthernet()
{

client.stop();

Serial.println("Connecting Arduino to network...");
Serial.println();

delay(1000);

// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}

delay(1000);
}

//dtostrf (float to String)
char *dtostrf (float val, signed char width, unsigned char prec, char *sout)
{
char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;
}

↧

gregp228 on Updating Latitude and Longitude from ThingSpeak Communication Library for Arduino

$
0
0

The ThingSpeak Communication Library for Arduino has location functions:

ThingSpeak KEYWORD1
begin KEYWORD2
writeField KEYWORD2
setField KEYWORD2
setLatitude KEYWORD2
setLongitude KEYWORD2
setElevation KEYWORD2
writeRaw KEYWORD2
writeFields KEYWORD2
readFloatField KEYWORD2
readIntField KEYWORD2
readLongField KEYWORD2
readStringField KEYWORD2
readRaw KEYWORD2
getLastReadStatus KEYWORD2

I am unable to get these to work.

int setLatitude(float latitude)
{
#ifdef PRINT_DEBUG_MESSAGES
Serial.print("ts::setLatitude(latitude: "); Serial.print(latitude,3); Serial.println("\")");
#endif
this->nextWriteLatitude = latitude;
return OK_SUCCESS;
};

/**
* @brief Set the longitude of a multi-field update.
* To record latitude, longitude and elevation of a write, call setField() for each of the fields you want to write, setLatitude() / setLongitude() / setElevation(), and then call writeFields()
* @param longitude Longitude of the measurement (degrees E, use negative values for degrees W)
* @return HTTP status code of 200 if successful. See getLastReadStatus() for other possible return values.
* @see setField(), setLatitude(), setElevation(), writeFields()
* @code
void loop() {
int sensor1Value = analogRead(A0);
float sensor2Voltage = analogRead(A1) * (5.0 / 1023.0);
String sensor3Meaning;
int sensor3Value = analogRead(A2);
if (sensor3Value < 400) {
sensor3Meaning = String("Too Cold!");
} else if (sensor3Value > 600) {
sensor3Meaning = String("Too Hot!");
} else {
sensor3Meaning = String("Just Right");
}
long timeRead = millis();

ThingSpeak.setField(1, sensor1Value);
ThingSpeak.setField(2, sensor2Voltage);
ThingSpeak.setField(3, sensor3Meaning);
ThingSpeak.setField(4, timeRead);
setLatitude(42.2833);
setLongitude(-71.3500);
setElevation(100);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(20000);
}
* @endcode
*/

The example from the library however does not work and setLatitude() will not compile

any help with this would be appreciated

12

↧
↧

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

$
0
0

i have same problem with sinet666, and i already look at the example code but dont have any idea with that tho. Anyone can help with other example for arduino and esp8266?

↧

dave1829 on i have 4 TS channels, how to update 16 values via one Arduino sketch?

$
0
0

 i have tried so many iterations!

for example:

#include "ThingSpeak.h"

unsigned long upstairsPlenumCh1APIKeyChNum = xx;
const char * upstairsPlenumCh1APIKey = "123";

unsigned long upstairsPlenumCh2APIKeyChNum = yy;
const char * upstairsPlenumCh2APIKey = "456";

unsigned long upstairsPlenumCh3APIKeyChNum = zz;
const char * upstairsPlenumCh3APIKey = "789";

unsigned long upstairsPlenumCh4APIKeyChNum = ww;
const char * upstairsPlenumCh4APIKey = "987";

then do stuff

then:

void dataLoggingThingspeakCh1()
{ //sends the Ch1 variables to Thingspeak
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 1, medianRoofTemp, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 2, roofVapourPres, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 3, medianHouseTemp, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 4, houseVapourPres, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 5, medianExternTemp, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 6, externVapourPres, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 7, medianLivingTemp, upstairsPlenumCh1APIKey);
ThingSpeak.writeField(upstairsPlenumCh1APIKeyChNum, 8, livingVapourPres, upstairsPlenumCh1APIKey);

}

void dataLoggingThingspeakCh2()
{ //sends the Ch2 variables to Thingspeak
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 1, medianBed1Temp, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 2, bed1VapourPres, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 3, medianBed2Temp, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 4, bed2VapourPres, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 5, roofDewPoint, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 6, houseDewPoint, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 7, externDewPoint, upstairsPlenumCh2APIKey);
ThingSpeak.writeField(upstairsPlenumCh2APIKeyChNum, 8, livingDewPoint, upstairsPlenumCh2APIKey);

}

void dataLoggingThingspeakCh3()
{ //sends the Ch3 variables to Thingspeak
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 1, bed1DewPoint, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 2, bed2DewPoint, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 3, setTarget, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 4, setCooling, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 5, setWarming, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 6, setShutOffFunction, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 7, setLivingOutlet, upstairsPlenumCh3APIKey);
ThingSpeak.writeField(upstairsPlenumCh3APIKeyChNum, 8, setBedsOutlet, upstairsPlenumCh3APIKey);

dataLoggingThingspeakCh4();
}

void dataLoggingThingspeakCh4()
{ //sends the Ch4 variables to Thingspeak
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 1, closeLivingOutlet, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 2, closeBedroomsOutlet, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 3, setToiletOff, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 4, upstairsPlenumSmoke, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 5, upstairsPlenumCO2, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 6, basementPlenumSmoke, upstairsPlenumCh4APIKey);
ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 7, basementPlenumCO2, upstairsPlenumCh4APIKey);
// ThingSpeak.writeField(upstairsPlenumCh4APIKeyChNum, 8,NEWVARIABLE, upstairsPlenumCh4APIKey);

}

 

but getting error:

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

any suggestions?

↧

rw950431 on i have 4 TS channels, how to update 16 values via one Arduino sketch?

$
0
0

Did you look at the "WriteMultipleVoltages" example from the TS library? Even if you solve your compile errors it wont work because TS limits updates to one every 15 seconds per channel so only the field 1 update will succeed.

Its possible you have the wrong board type set, can you compile and run any of the example programs that came with the library? I always find that getting the examples to run is a good way to ensure your environment is set up correctly.

Alternatively I note that the examples use "float" for the value but the error implies you supply "double" - perhaps this is tripping up the compiler?

↧

josepbj on ESP8266 + Arduino

$
0
0

Hey there,

The last week I was working to create an sketch that uploads and retrieve data from a thingspeak channel. Even though it was quite tough (the reason why I am sharing it), I did quite quick and not taking in consideration much of clean and reusable code. I will work in the next days to clean everything and work on a library. 

Here you have the GitHub link if you want to take a look and get some ideas.

 

Josep

 

https://github.com/josepbordesjove/ESP8266_IoT

↧
↧

angeloventura on thingspeak with enc28j60 & arduino

$
0
0

Great Job!!!
Which library works??? Do you have a link???

Thank u

↧

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

$
0
0

 Hi there

 

I am completely stuck and would really like some input.  I can get a stable connection to Thingspeak, but all my attempts to post data re unsuccessful.  I can either post an empty entry (It shows I have a new entry, with null values for the fields) or I can get a 400 Bad Request returned, but that's it.  Any pointers will be welcome!

I am using Wifly.h and connects successfully to the wifi and external sites.

Here is the code for the Bad Request:

I call this function in my main loop:

ThingSpeakUpdate("field1="+String(x)+"&field2="+String(y));

And here is the function:

void ThingSpeakUpdate(String tsData)
{
Serial.println("Data string: " + tsData);

Serial.println("...Connecting to Thingspeak");

// Connecting and sending data to Thingspeak

if(Wifly.connect("api.thingspeak.com","80"))
{
Serial.println("...Connection succesful, updating datastreams");

Wifly.println("POST /update HTTP/1.1");
Wifly.println("Host: api.thingspeak.com");
Wifly.println("Connection: close");
Wifly.println("X-THINGSPEAKAPIKEY: "+myWriteAPIKey);
Wifly.println("Content-Type: application/x-www-form-urlencoded");
Wifly.println("Content-Length: ");
Wifly.println(tsData.length());
Wifly.println();
Wifly.println(tsData);
delay(200);
Serial.println("Thingspeak update sent.");
}
else{
// Failed to connect to Thingspeak
Serial.println("Unable to connect to Thingspeak.");
}

↧

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

$
0
0

I managed to solve the issue.  Here are the steps that might help, even for those who uses other hardware and libraries:

1. I knew that the url to post worked when I put it in a web browser - it updated my feed:

https://api.thingspeak.com/update?key=xxxxxxxxxxxxxx&field1=10    (obviously I replaced the x's with my write key)

2. I was thinking that my shield was adding info to my header and this caused  the "Bad Request" error, so I went to 

http://web-sniffer.net/

and posted my url into the box provided.  This then returned the info sent to the server and it looked like this:

Connect to 52.7.53.111 on port 443 ... ok

GET /update?key=PONK48XZ3V2APBKW&field1=10 HTTP/1.1[CRLF]
Host: api.thingspeak.com[CRLF]
Connection: close[CRLF]
User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)[CRLF]
Accept-Encoding: gzip[CRLF]
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]
Cache-Control: no-cache[CRLF]
Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]
Referer: http://web-sniffer.net/[CRLF]
[CRLF]


From there I created my commands to the website by changing the code in my function.  This is the working function:

Command to call the function in my main loop:

ThingSpeakUpdate("field1="+String(x)+"&field2="+String(y));
delay(15000);


And here is my working function:

void ThingSpeakUpdate(String tsData)
{
 Serial.println("Data string: " + tsData);

 Serial.println("...Connecting to Thingspeak");

 // Connecting and sending data to Thingspeak
 
 if(Wifly.connect("api.thingspeak.com","80"))
 {
 Serial.println("...Connection succesful, updating datastreams");
 
 Wifly.println("GET /update?key=PONK48XZ3V2APBKW&"+tsData+" HTTP/1.1");
 Wifly.println("Host: api.thingspeak.com");
 Wifly.println("Connection: close");
 delay(200);
 Serial.println("Thingspeak update sent.");
 }
 else{
 // Failed to connect to Thingspeak
 Serial.println("Unable to connect to Thingspeak.");
 }

Interestingly enough, I did not have to specify the packet lenght.  I hope this helps others aswell.
↧

sayanbhattacharyya on HackPOD: Smartphone-like MCU platform powered by Arduino

$
0
0

Hi guys,

Let me introduce you to HackPOD, an advanced microcontroller platform we developed over the last 2 years.

HackPOD is a fast and powerful electronics development platform in a portable smartphone form factor. It is based on a 32-bit ARM Cortex-M4 chip running at a clock speed of 72 MHz and is programmable by the Arduino IDE and C language. It also features an integrated touchscreen LCD, in-built protoboard and SMT space, expandable memory , and a rechargeable battery.

Please check it out at

Our website: https://hackpod.github.io

Our blog: https://hackpod.gitbooks.io/blog/content/

Our Facebook page: http://www.facebook.com/gethackpod

We welcome you to post your feedback and suggestions. Thanks in advance for your support.

We will be crowdfunding  via Indiegogo starting this June 15th. To be notified when we launch, please fill this form: https://hackpod.github.io/notify.

To avail an Early Bird offer on HackPOD, you may sign up here: https://hackpod.github.io/earlybird.

↧
↧

Smitty on Multiple 1 Wire Bus on Digital Pin ....

$
0
0

How best to achieve this ...

Not getting a successful compile from the below sketch ....

Very much a newb with ThingSpeak and Arduino ... 

/* Arduino Mega 2560 WiFi Weather Station
* 
* July 2016 By John D Smith ZL4CO
* */

 

#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ThingSpeak.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(0.0.0.0);

// Initialize Arduino Ethernet Client
EthernetClient client;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

// ThingSpeak Settings
unsigned long myChannelNumber = secret;
const char * myWriteAPIKey = "";

// There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors.

// 1 Wire Data wire is plugged into Digital pin 12 on the Arduino
#define ONE_WIRE_BUS 12

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of the 1-Wire temp sensors.

DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(void)

{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Temp1, 10);
sensors.setResolution(Temp2, 10);

ThingSpeak.begin(client);
}

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop (void)
{
delay(10000);*/
Serial.print("Getting temperatures...

");
sensors.requestTemperatures();

Serial.print("Temp 1 is: ");
printTemperature(Temp1);
Serial.print("

");
Serial.print("Temp 2 is: ");
printTemperature(Temp2);
Serial.print("

");

Serial.print("

");

delay(200);
}

Cry
//Update the ThingSpeak Channel

float pinVoltage = sensors.(Temp1) ;
ThingSpeak.setField(1,pinVoltage);
pinVoltage = sensors.(Temp2)
ThingSpeak.setField(2,pinVoltage);

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

Serial.print("Temperatures Uploaded to Cloud...

");
delay(80000);

It is in this part here I am not sure how to Access my Temp1 and Temp2 values for ThingSpeak

↧

rw950431 on Multiple 1 Wire Bus on Digital Pin ....

$
0
0

For a start the Thingspeak section is outside the loop() so probably wont compile. Use the arduino IDE Tools->Format menu to nicely indent your code so its easy to pick these things up.

 

I suggest you work through some of the Examples that come with the Thingspeak library and go from there.

↧

jpsabo on Problem using Thingspeak Library with local Thingspeak installation

$
0
0

Thanks for the posting…this is just what I needed to get an Arduino Yun talking to my local ThingSpeak server (ubuntu-14.04.4-server-amd64 on VMWare Fusion 6.0.6):

void setup() {

// pass custom IP address (10.0.1.196) and port number (3000) to ThingSpeak

ThingSpeak.begin(client, IPAddress(10, 0, 1, 196), 3000);              

…other setup code

}

 

Complete test sketch

// Upload random numbers to a local ThingSpeak server.
// ThingSpeak server is running as a virtual machine in VMWare.
// Optimally, assign a static IP address to the virtual machine so that IP address can stay fixed in the sketch.

#include <ThingSpeak.h>

#define myChannelNumber put_ThingSpeak_channel_here
#define myWriteAPIKey "API write key goes inside the quotes"

#include <YunClient.h>
YunClient client;

void setup() {
pinMode(13, OUTPUT); // initialize digital pin 13 as an output

Bridge.begin(); // start Bridge

ThingSpeak.begin(client, IPAddress(10, 0, 1, 196), 3000); // pass custom IP address and port (local VMWare ThingSpeak server) to ThingSpeak
}

void loop() {
float v1, v2, v3, v4;

digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500);
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500);
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500);
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW

ThingSpeak.setField(1, random(5, 9) * 10.0F / random(5, 9) * 1.0F); // place data into ThingSpeak fields
ThingSpeak.setField(2, random(5, 9) * 10.0F / random(5, 9) * 1.0F);
ThingSpeak.setField(3, random(5, 9) * 10.0F / random(5, 9) * 1.0F);
ThingSpeak.setField(4, random(5, 9) * 10.0F / random(5, 9) * 1.0F);

ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); // Write the fields all at once to the ThingSpeak server

delay(15000); // delay next write for 15 sec (ThingSpeak minimum update frequency)
}

↧

Luis_Filipe on Arduino Mega with yun shield

$
0
0

Hello guys,

 

I want to collect data to thingspeak by a analog A0 input with WiFi communication, the problem is that I´cannot setup by yun shield to send data.

I test with a ethernet shield and everything is correct, but with the yun shield the data is not be send, look the code:

 

#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"
#else
#include "ThingSpeak.h"
#endif
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0
#define USE_WIFI_SHIELD

#include "BridgeClient.h"
BridgeClient client;

unsigned long myChannelNumber = 1XX47;
const char * myWriteAPIKey = "XXXXXXXXXXT7SVDMCJ5";

#include <SPI.h>
#include <WiFi.h>
char ssid[] = "MySSID"; 
char pass[] = "MyPASSWORD"; 
int status = WL_IDLE_STATUS;

void setup() {
Bridge.begin();
WiFi.begin(ssid, pass);

ThingSpeak.begin(client);
}

void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);

ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}

 

what is wrog, any ideia?

 

Thanks in advance

↧
↧

hickse on Not all DS18B20 sensors present on ThingSpeak

$
0
0

I have successfully compiled a sketch that collects and displays an analog temperature, 2 (of 4)  DS18B20 sensors, and a digital temperature and humidity output from a DHT11 sensor.  All sensor data mirrors on the COM port, but 2 of the DS18B20 fields do not display on ThingSpeak.  When I include those fields no data is updated on ThingSpeak.  When I comment them out all other data is updated.

The sketch follows:

/*
WriteMultipleSensors
This sketch builds upon V5 by trying to incorporate 2 more DS18B20 sensors for Field 4 and 5
independant of the Field 2 and 3 sensors

This sketch successfully logs 1 analog, 2 DS18B20 signals, and 1 set of DHT11 data.
It doesn't transmit Field 3 and Field 4 from the DS18B20 sensor. Don't know if it is a voltage issue or a
String composition limitation

*/
#include "ThingSpeak.h"
#include <OneWire.h>
#include <SPI.h>
#include <DallasTemperature.h>
#include <DHT.h>
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet2.h> // Make sure there is a 2 after Ethernet!
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;

// Analog Pin setup -
// On Arduino: 0 - 1023 maps to 0 - 5 volts
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0

// Define DHT11 for room temperature and humidity measurement
#define DHTPIN 4 // what digital pin we're connected to.. Digital Pin 4 in this case
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

// DS1820 Setup.... A oneWire instance to communicate with any OneWire devices
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
//#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of 1-Wire temp sensors.
DeviceAddress HPWH_TempOut = { 0x28, 0x37, 0x08, 0x1E, 0x07, 0x00, 0x00, 0x1F }; // Tested
DeviceAddress HPWH_TempIn = { 0x28, 0x80, 0x8D, 0x1C, 0x07, 0x00, 0x00, 0x83 }; // Tested
DeviceAddress DWH_TempOut = { 0x28, 0x92, 0x38, 0x1D, 0x07, 0x00, 0x00, 0xA4 }; // Not working when DHT11 robs power
DeviceAddress DWH_TempIn = { 0x28, 0xA4, 0xA8, 0x2A, 0x07, 0x00, 0x00, 0x82 }; // Shows at Serial Print but not on ThinkSpeak: maybe voltage problem

unsigned long myChannelNumber = 130737;
const char * myWriteAPIKey = "F0QA9UVAQWWQ0G1E";

void setup() {
// Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
Ethernet.begin(mac);

ThingSpeak.begin(client);
sensors.begin();
// set the resolution to 10 bit (way more than I need)
sensors.setResolution(HPWH_TempOut, 10);
sensors.setResolution(HPWH_TempIn, 10);
sensors.setResolution(DWH_TempOut, 10);
sensors.setResolution(DWH_TempIn, 10);

// Temp debugging of the DHT11 sensor
Serial.println("DHTxx test!");
dht.begin();
}

void loop() {

// Reading DHT11 temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int humidity = h * 1.25; // Correction multiplier
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Read the input on each pin, convert the reading, and set each field to be sent to ThingSpeak.

// On Arduino: 0 - 1023 maps to 0 - 5 volts
float pinVoltage = analogRead(A0) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
float TMP36 = (pinVoltage - 0.5) * 100 * 9 / 5 + 32;
//Print Temperatures
Serial.print ("Getting temperatures...

");
Serial.print("TMP36... Room Temperature....");
Serial.println(TMP36);
sensors.requestTemperatures();
float HPwhTempOut = sensors.getTempF(HPWH_TempOut);
float HPwhTempIn = sensors.getTempF(HPWH_TempIn);
float DWHTempOut = sensors.getTempF(DWH_TempOut);
float DWHTempIn = sensors.getTempF(DWH_TempIn);

Serial.print("Heat Pump Water Temp out is:(Field 2)");
Serial.print(HPwhTempOut);
Serial.print("F: ");
Serial.print("

");

Serial.print("Heat Pump Water Temp in is: (Field 3)");
Serial.print(HPwhTempIn);
Serial.print("F: ");
Serial.print("

");

Serial.print("Water tank Temp out is: (Field 4)");
Serial.print(DWHTempOut);
Serial.print("F: ");
Serial.print("

");

Serial.print("Water tank Temp in is: (Field 5)");
Serial.print(DWHTempIn);
Serial.print("F: ");
Serial.print("

");

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.print("DHT11 Temperature: ");
Serial.print(f*.9);
Serial.println(" *F\t");

// The following lines of code convert the DHT11 individual values to strings that ThingSpeak can us
String(h,DEC);
String(f,DEC);

/*//The following lines of code convert DS19B20 to a string value that ThingSpeak can use
String(HPwhTempOut,DEC); // ThingSpeak Field 2
String(HPwhTempIn, DEC); // ThingSpeak Field 3
String(DWHTempOut, DEC); // ThingSpeak Field 4
String(DWHTempIn, DEC); // ThingSpeak Field 5
*/
/*char buffer[12];
String tempStr=dtostrf(HPwhTempOut,6,2,buffer);
String tempStr2=dtostrf(HPwhTempIn,6,2,buffer);
String tempStr3=dtostrf(DWHTempOut,6,2,buffer);
*/
ThingSpeak.setField(1,TMP36);
//pinVoltage = analogRead(A1) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
ThingSpeak.setField(2,HPwhTempOut);

ThingSpeak.setField(3,HPwhTempIn);

//ThingSpeak.setField(4,DWHTempOut);

//ThingSpeak.setField(5,DWHTempIn);

ThingSpeak.setField(6,f);

ThingSpeak.setField(7,humidity);
// pinVoltage = analogRead(A7) * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
//ThingSpeak.setField(8,pinVoltage);

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

delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}

↧

rw950431 on Not all DS18B20 sensors present on ThingSpeak

$
0
0

Have you tried setting DWHTempIn to a fixed value and testing if that updates correctly?  Are you sure you have enabled channels 4 and 5 on your thingspeak channel and that the value is within the range you set? 

Does it work if you disable the DHT11 and send only the DS1820 temps?

I've not used the arduino TS client but these may narrow down the problem a bit.

 

(You may wish to change your API key now that you've posted the old one to the internet...)

↧

hickse on Not all DS18B20 sensors present on ThingSpeak

$
0
0

Thanks for looking at this.  I tried to set DWHTemp to a fixed value and uncomment it and that did not work.

When I disable the DHT11 temp I can include 1 more DS18B20 sensor and get it to show in a ThingSpeak Field for a total of 5 fields.

That made me think there is a limit to 4 - 5 Fields without changing some parameter.

I then created a sketch with 8 identical analog Fields. None presented to ThingSpeak.

I then eliminated all but the first Field and it showed 1 field on ThingSpeak.... 

I then included 1 more and tested out the presentation.  2 fields presented.

I than kept incrementing the number of fields included in the sketch and when I got to 5 none were presenting / updating.

This is consistent with what I'm experiencing in the original sketch.  This indicates to me that it isn't' an issue of String configuration, as I tried the above test with and without the variable being labeled as a String.

Any thoughts or guidance would be very much appreciated.

↧
Viewing all 172 articles
Browse latest View live