ThingSpeak arduino error with unsigned long | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
ThingSpeak arduino error with unsigned long
No permission to create posts
May 13, 2019
3:43 am
Avatar
alejandrogc259
New Member
Members
Forum Posts: 1
Member Since:
May 13, 2019
sp_UserOfflineSmall Offline

This is my code. The error is "redefinition of unsigned long int myChannelNumber.
Please I need help.

/*
ESP8266 --> ThingSpeak Channel

This sketch sends the value of Analog Input (A0) to a ThingSpeak channel
using the ThingSpeak API (https://www.mathworks.com/help/thingspeak).

Requirements:

* ESP8266 Wi-Fi Device
* Arduino 1.8.8+ IDE
* Additional Boards URL: http://arduino.esp8266.com/stable/package_esp8266com_index.json
* Library: esp8266 by ESP8266 Community
* Library: ThingSpeak by MathWorks

ThingSpeak Setup:

* Sign Up for New User Account - https://thingspeak.com/users/sign_up
* Create a new Channel by selecting Channels, My Channels, and then New Channel
* Enable one field
* Enter SECRET_CH_ID in "secrets.h"
* Enter SECRET_WRITE_APIKEY in "secrets.h"

Setup Wi-Fi:
* Enter SECRET_SSID in "secrets.h"
* Enter SECRET_PASS in "secrets.h"

Tutorial: http://nothans.com/measure-wi-fi-signal-levels-with-the-esp8266-and-thingspeak

Created: Feb 3, 2017 by Hans Scharler (http://nothans.com)
*/

#include "ThingSpeak.h"
#include "secrets.h"

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

#include

char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key index number (needed only for WEP)
WiFiClient client;

void setup() {
Serial.begin(115200);
delay(100);

WiFi.mode(WIFI_STA);

ThingSpeak.begin(client);
}

void loop() {

// Connect or reconnect to WiFi
if (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("
Connected.");
}

// Measure Analog Input (A0)
int valueA0 = analogRead(A0);

// Write value to Field 1 of a ThingSpeak Channel
int httpCode = ThingSpeak.writeField(myChannelNumber, 1, valueA0, myWriteAPIKey);

if (httpCode == 200) {
Serial.println("Channel write successful.");
}
else {
Serial.println("Problem writing to channel. HTTP error code " + String(httpCode));
}

// Wait 20 seconds to uodate the channel again
delay(20000);
}

May 13, 2019
11:15 am
Avatar
Vinod

MathWorks
Members
Forum Posts: 327
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

Have you tried starting from the examples here: https://github.com/mathworks/thingspeak-arduino

The library provides you high level functions that will make your life easier compared to making the requests yourself.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
31 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Fathima22, jefflam1994, harrydawson, markpaul7931, sgarsvk2rdx, Win Win

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457