čtení z thingspeak
čtení z thingspeak
Ahoj všem, jde nějak načítat hodnoty z thingspeaku do arduina? Všude jsou návody na odesílání ale čtení jsem nenašel.
Díky
Díky
https://arze.cz - ARduino Zapojení Elektronika
Re: čtení z thingspeak
Tady něco takového řeší https://arduino.stackexchange.com/quest ... uino-setup
Re: čtení z thingspeak
Co potřebuješ načítat? Jenom poslední hodnotu, nebo celou databázi? Teď jsem to řešil v Pythonu, a jde to jedním řádkem.
-
- Příspěvky: 579
- Registrován: 01 srp 2017, 19:29
- Reputation: 0
- Bydliště: Poprad
- Kontaktovat uživatele:
Re: čtení z thingspeak
Toto je to, prečo používam vlastné riešenie furt, čo si sám naprogramujem v php. Vytiahnem si čo chcem a kedy chcem
Re: čtení z thingspeak
dobrý den, mám stejný dotaz jak na začátku vlákna. bohužel se mi nedaří to stejné. potřeboval bych do proměnné načít číslo, které jakkoliv dostanu na thingspeak. v odkazu:
https://api.thingspeak.com/channels/460 ... lds/1/last
je hodnota a tu bych rád načetl. poradí mi někdo jak co nejjednodušeji na to? chci se naučit pro další aplikace základ a to rozsvítit/zhasnout diodu podle načtené hodnoty z thingspeaku ...
děkuji za pomoc
https://api.thingspeak.com/channels/460 ... lds/1/last
je hodnota a tu bych rád načetl. poradí mi někdo jak co nejjednodušeji na to? chci se naučit pro další aplikace základ a to rozsvítit/zhasnout diodu podle načtené hodnoty z thingspeaku ...
děkuji za pomoc
Re: čtení z thingspeak
ak problém s pochopením tak súkromná správa
thingspeak_ipaddress find_send_themperature_esp8266.txt
Odosielanie/prijímanie/status=chat
Tento kód je meranie teploty a odoslanie,,,prijatie jednej poslednej teploty z poľa 8, odoslanie textu do STATUSU
Zistenie vonkajšej IP adresy a rozloženie text na štyri samostatné čísla ---je to akoby DDNS server na zistenie IP,,,lebo v routroch sú takmer všetky platené.....hodí sa to na kamery a podobne
IP sa odošle na 4 časti ako 4 čísla,,,alebo ak zmeníte text tak sa odošle do čatovacieho okna na thingspeak ( &status+váš text)
pozri status v kóde:
//you can write msg on THINGSPEAK, max 255 characters,,enable status on THINGSPEAK
postStr += "&status=";
postStr += "I love you";
čítanie z thingspeak,,,,pozri dolu od textu ..... // read from thingspeak
pr.2
thingspeak_ds18b20_public_ip_remote_led
ESP8266 ako client----čiže ak neverejná IP a neviete sa dostať do domácej siete z vonku tak je to vhodne na ovládanie ESP8266/ARDUINO s lan modulom.
zistenie IP=DDNS,,meranie teploty, a ovládanie LED pomocou čísla 55 a 66 z poľa 3
ak je 55 LED je ON,,,ak 66 LED je OFF,,,ak iné číslo tak sa nič nezmení.
thingspeak_ipaddress find_send_themperature_esp8266.txt
Odosielanie/prijímanie/status=chat
Tento kód je meranie teploty a odoslanie,,,prijatie jednej poslednej teploty z poľa 8, odoslanie textu do STATUSU
Zistenie vonkajšej IP adresy a rozloženie text na štyri samostatné čísla ---je to akoby DDNS server na zistenie IP,,,lebo v routroch sú takmer všetky platené.....hodí sa to na kamery a podobne
IP sa odošle na 4 časti ako 4 čísla,,,alebo ak zmeníte text tak sa odošle do čatovacieho okna na thingspeak ( &status+váš text)
pozri status v kóde:
//you can write msg on THINGSPEAK, max 255 characters,,enable status on THINGSPEAK
postStr += "&status=";
postStr += "I love you";
čítanie z thingspeak,,,,pozri dolu od textu ..... // read from thingspeak
Kód: Vybrat vše
// ARDUINO IDE 1.6.7,,,scratch mDNS_Web_Server
//for ESP8266,,,,,If arduino - you change code for WIFI and ...
//functions:
// temperature on thingspeak
// find out public ip
// extract ip or mac address on parts
// sending external IP address on Thingspeak to four fields
// sending test msg on THINGSPEAK Status
// read from thingspeak-- no complet=example // read one field
// deep sleeping for ESP8226 - if you enable
//source:
//https://stackoverflow.com/questions/35227449/convert-ip-or-mac-address-from-string-to-byte-array-arduino-or-c
//https://www.ipify.org
//https://github.com/mathworks/thingspeak-arduino
//https://uk.mathworks.com/help/thingspeak/get-a-channel-feed.html
//
//setting for ARDUINO ide
// boards http://arduino.esp8266.com/package_esp8266com_index.json
// board: GENERIC ESP8266 MODULE or ADAFRUIT HUZZAH ESP8266 or for NODEMCU
// settings QIO 40MHz SERIAL 80MHz 4M ck 115200 com? AVRSIPmkll
//sleeping for ESP8266 E12 : it is on end of LOOP
//ESP.deepSleep(100e6); // 20e6 is 20 seconds,connect pin GPIO16=D0 on RST
/*
ESP8266 mDNS responder sample
This is an example of an HTTP server that is accessible
via http://esp8266.local URL thanks to mDNS responder.
Instructions:
- Update WiFi SSID and password as necessary.
- Flash the sketch to the ESP8266 board
- Install host software:
- For Linux, install Avahi (http://avahi.org/).
- For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
- For Mac OSX and iOS support is built in through Bonjour already.
- Point your browser to http://esp8266.local, you should see a response.
*/
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//define Data Types
byte bytes[4];
String ddd = "111.111.111.111"; //after power on=reset only
String line = "";
// replace with your channel’s thingspeak API key,
String apiKey = "thingspeakkey";
// replace with your NAME=SSID and PASSWORD for router,,with " "
const char* ssid = "meno router";
const char* password = "heslo";
//server THINGSPEAK
const char* server = "api.thingspeak.com";
// DS18B20 plug to pin GPIO12 ESP8266-12 = D6(MISO)
#define ONE_WIRE_BUS 2
// define resolution for sensors 9bit/0.5 10bit/0.25 11bit/0.125 12bit/0.0625
#define TEMPERATURE_PRECISION 11
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;
float teplota;
String termOUT;
String termIN;
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println();
Serial.println();
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("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// search for devices on the bus and assign based on an index.
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
// set the resolution to 9 bit
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
Serial.print("Device 1 Resolution: ");
Serial.print(sensors.getResolution(outsideThermometer), DEC);
Serial.println();
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
void printResolution(DeviceAddress deviceAddress)
{
Serial.print("Resolution: ");
Serial.print(sensors.getResolution(deviceAddress));
Serial.println();
}
// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.print(" ");
printResolution(deviceAddress);
Serial.println();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
// print the device information
Serial.print("Teplota vnutri: ");
printData(insideThermometer);
Serial.print("Teplota vonku: ");
printData(outsideThermometer);
float tint = sensors.getTempC(insideThermometer);
float tout = sensors.getTempC(outsideThermometer);
// thingspeak needs minimum 15 sec delay between updates
//change delay for next update
delay(20000);
// find out public ip
// it finds out ext.IP address with html for arduino,,It should only send an address without html text,,,read more on ipify.org
//you can use other IP check servers to find out external IP address
if (client.connect("api.ipify.org", 80)) {
//Serial.println("connected");
client.println("GET /?format=txt HTTP/1.0");
client.println("Host: api.ipify.org");
client.println();
} else {
Serial.println("connection failed");
}
delay(50);
int b = 1;
while (client.connected()) {
b = b + 1;
line = client.readStringUntil('\n');
// part for IP address
Serial.println(line);
}
// find out public ip--end
// String to char for IP
//how it works---see sketch "extract ip or mac address on parts.txt"
char ipstr[20];
line.toCharArray(ipstr, 20);
const char* str = ipstr;
char sep = '.';
int maxBytes = 4;
int base = 10;
for (int i = 0; i < maxBytes; i++) {
bytes[i] = strtoul(str, NULL, base); // Convert byte
Serial.println(bytes[i]);
str = strchr(str, sep); // Find next separator
if (str == NULL || *str == '\0') {
break; // No more separators, exit
}
str++; // Point to next character after separator
}
// String to char for IP--end
//preparing string - IP to String for Thingspeak
String abc = "&field5=";
abc += String(bytes[0]);
abc +="&field6=";
abc += String(bytes[1]);
abc +="&field7=";
abc += String(bytes[2]);
abc +="&field8=";
abc += String(bytes[3]);
// if it does not find out IP,it will not send ZERO
//CHANGE code if you want to send new IP address at a change only without minute update
if (bytes[0] > 0 ) {
ddd = abc;
}
client.stop();
// find out public ip---end
// data to thingspeak
if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com
String postStr = apiKey;
postStr +="&field1=";
postStr += String(tint);
postStr +="&field2=";
postStr += String(tout);
//add IP
postStr += ddd;
//you can write msg on THINGSPEAK, max 255 characters,,enable status on THINGSPEAK
postStr += "&status=";
postStr += "I love you";
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
Serial.println("thing text");
client.stop();
// data to thingspeak - end
// read from thingspeak
Serial.println("read TS…");
if (client.connect(server,80)){
client.println("GET /channels/179933/fields/8/last") ;
client.println("Host: api.thingspeak.com");
client.println();
} else {
Serial.println("connection failed");
}
delay(50);
int a = 1;
while (client.connected()) {
a = a + 1;
String thinga = client.readStringUntil('\n');
Serial.println(thinga);
}
client.stop();
Serial.println("stop connection…");
// read from thingspeak - end
//sleeping enable/disable
// 20e6 is 20 seconds,connect pin GPIO16=D0 on RST
//ESP.deepSleep(100e6);
}
pr.2
thingspeak_ds18b20_public_ip_remote_led
ESP8266 ako client----čiže ak neverejná IP a neviete sa dostať do domácej siete z vonku tak je to vhodne na ovládanie ESP8266/ARDUINO s lan modulom.
zistenie IP=DDNS,,meranie teploty, a ovládanie LED pomocou čísla 55 a 66 z poľa 3
ak je 55 LED je ON,,,ak 66 LED je OFF,,,ak iné číslo tak sa nič nezmení.
Kód: Vybrat vše
// ARDUINO IDE 1.6.7,,,scratch mDNS_Web_Server
// temperature on thingspeak, you can upate new value after 10s or 20s,find out more on thingspeak
// read from thingspeak-- no complet
// find out public ip
//read from thingspeak and remote LED,,, if field1 contains: 55 - led=high,,66 - led=low
#include <ESP8266WebServer.h>
/*
ESP8266 mDNS responder sample
This is an example of an HTTP server that is accessible
via http://esp8266.local URL thanks to mDNS responder.
Instructions:
- Update WiFi SSID and password as necessary.
- Flash the sketch to the ESP8266 board
- Install host software:
- For Linux, install Avahi (http://avahi.org/).
- For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
- For Mac OSX and iOS support is built in through Bonjour already.
- Point your browser to http://esp8266.local, you should see a response.
*/
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
// boards http://arduino.esp8266.com/package_esp8266com_index.json
// GENERIC ESP8266 MODULE
// settings QIO 40MHz SERIAL 80MHz 4M ck 115200 com? AVRSIPmkll
#include <OneWire.h>
#include <DallasTemperature.h>
// replace with your channel’s thingspeak API key,
String apiKey = " thingspeak key";
const char* ssid = "meno router";
const char* password = "heslo router";
const char* server = "api.thingspeak.com";
// DS18B20 plug to pin GPIO12 ESP8266-12
#define ONE_WIRE_BUS 2
// define resolution for sensors 9bit/0.5 10bit/0.25 11bit/0.125 12bit/0.0625
#define TEMPERATURE_PRECISION 11
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;
float teplota;
String termOUT;
String termIN;
int led = 13; //13 is D7 on ESP8266
WiFiClient client;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println();
Serial.println();
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("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// search for devices on the bus and assign based on an index.
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
// set the resolution to 9 bit
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
Serial.print("Device 1 Resolution: ");
Serial.print(sensors.getResolution(outsideThermometer), DEC);
Serial.println();
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
void printResolution(DeviceAddress deviceAddress)
{
Serial.print("Resolution: ");
Serial.print(sensors.getResolution(deviceAddress));
Serial.println();
}
// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.print(" ");
printResolution(deviceAddress);
Serial.println();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
// print the device information
Serial.print("Teplota vnutri: ");
printData(insideThermometer);
Serial.print("Teplota vonku: ");
printData(outsideThermometer);
float tint = sensors.getTempC(insideThermometer);
float tout = sensors.getTempC(outsideThermometer);
// data to thingspeak
if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com
String postStr = apiKey;
postStr +="&field1=";
postStr += String(tint);
postStr +="&field2=";
postStr += String(tout);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
Serial.println("thing text");
client.stop();
// data to thingspeak - end
// read from thingspeak
Serial.println("read TS…");
if (client.connect(server,80)){
client.println("GET /channels/208474/fields/3/last") ;
client.println("Host: api.thingspeak.com");
client.println();
} else {
Serial.println("connection failed");
}
delay(50);
int a = 1;
while (client.connected()) {
a = a + 1;
String line = client.readStringUntil('\n');
Serial.println(line);
//define what number you will use for remote LED
if (line == "55" ||line == "55.0" || line == "55.00") {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
if (line == "66" ||line == "66.0" || line == "66.00") {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
client.stop();
Serial.println("Waiting…");
// read from thingspeak - end
// thingspeak needs minimum 15 sec delay between updates
delay(20000);
// find out public ip
if (client.connect("api.ipify.org", 80)) {
//Serial.println("connected");
client.println("GET /?format=txt HTTP/1.0");
client.println("Host: api.ipify.org");
client.println();
} else {
Serial.println("connection failed");
}
delay(50);
int c = 1;
while (client.connected()) {
c = c + 1;
String line = client.readStringUntil('\n');
Serial.println(line);
}
client.stop();
}
Re: čtení z thingspeak
Po delší době si odpovím. Vše jsem vyřešil a mám postavený zobrazovač na LED displej. Více info na mém webu. https://arze.cz
https://arze.cz - ARduino Zapojení Elektronika
Kdo je online
Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 4 hosti