20-01-2017, 23:48
Witam,
W jaki sposób wysłać do Thingspeaka dwie wartości (np z analogowych wejsc A0 i A1) na raz. Od razu mowie ze zdublowanie polecenia Thingspeak.writeField z przypisaniem innego fielda nie działa.
W jaki sposób wysłać do Thingspeaka dwie wartości (np z analogowych wejsc A0 i A1) na raz. Od razu mowie ze zdublowanie polecenia Thingspeak.writeField z przypisaniem innego fielda nie działa.
Kod:
#include "ThingSpeak.h"
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
// On Arduino: 0 - 1023 maps to 0 - 5 volts
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0
unsigned long myChannelNumber = moj nr;
const char * myWriteAPIKey = "api klucz";
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac);
ThingSpeak.begin(client);
}
void loop()
{
int sensorValue = analogRead(A0);
int sensorValue2 = analogRead(A1);
float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
Serial.println(sensorValue);
Serial.println(voltage);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey); <- działa
ThingSpeak.writeField(myChannelNumber, 2, sensorValue2, myWriteAPIKey); <- to już nie działa
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}