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

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)
}


Viewing all articles
Browse latest Browse all 172

Trending Articles