-->
Page 1 of 1

thingspeak send data seperately

PostPosted: Fri Jul 17, 2020 7:08 pm
by szevlin
I want to send 6 temperature values to a thingspeak channel and, 6 other temperature values to a different channel, how do I seperate the second 6 values from the 6 first, and how can I send them to the seperate channel? I got the code to send to one channel but I dont know how to send it seperately.

any help is appriciated

Code: Select all#include <DallasTemperature.h>
#include <OneWire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#define ONE_WIRE_BUS 5
#define TEMPERATURE_PRECISION 10
unsigned long myChannelNumber = 123456;
const char * myWriteAPIKey="xxxxx";
const char* ssid="xxxxx";
const char* password="xxxxx";
int fieldStart = 1;
int updatePeriod = 15;
int status = WL_IDLE_STATUS;
WiFiClient  client;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int numberOfDevices;
DeviceAddress tempDeviceAddress;
void setup() {
 Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
  pinMode(A0,INPUT);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password); 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");}
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  ThingSpeak.begin(client);
  sensors.begin();
  numberOfDevices = sensors.getDeviceCount();
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");
  Serial.print("Parasite power is: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  for(int i=0;i<numberOfDevices; i++)
  {if(sensors.getAddress(tempDeviceAddress, i)){
    Serial.print("Found device ");
    Serial.print(i, DEC);
    Serial.print(" with address: ");
    printAddress(tempDeviceAddress);
    Serial.println();   
    Serial.print("Setting resolution to ");
    Serial.println(TEMPERATURE_PRECISION, DEC);
    sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);   
    Serial.print("Resolution actually set to: ");
    Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
    Serial.println();  }else{
    Serial.print("Found ghost device at ");
    Serial.print(i, DEC);
    Serial.print(" but could not detect address. Check power and cabling");}}}
void printAddress(DeviceAddress deviceAddress)
{for (uint8_t i = 0; i < 8; i++){
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);}}
void loop() {
  sensors.requestTemperatures();
  for (int i=0; i<=(numberOfDevices - 1); i++){
    float temp=sensors.getTempCByIndex(i);
    ThingSpeak.setField(i+fieldStart,temp);
    Serial.println("Sensor #:");
    Serial.println(i);
    Serial.println("Temperature:");
    Serial.println(temp);}
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    Serial.println("Data sent to ThinkSpeak");
    delay(updatePeriod * 1000);}

Re: thingspeak send data seperately

PostPosted: Sat Jul 18, 2020 2:58 am
by Bonzo
Have you tried:
Code: Select all  ThingSpeak.writeFields(myChannelNumber1, myWriteAPIKey);
    Serial.println("Data sent to ThinkSpeak");
delay(100);
  ThingSpeak.writeFields(myChannelNumber2, myWriteAPIKey);
    Serial.println("Data sent to ThinkSpeak");