Veri Gönder¶
Veri göndermek için öncelikle cihaz eklemeniz gerekir. Cihaz oluşturulduğunda size özel okuma ve yazma “API KEY” üretilerek belirlenen erişim metoduna göre (POST, GET, POST/GET) veri işlemi gerçekleştirilir.
Örneğin; Cihazımız ısı, ışık, hareket, bar ve nem değerlerini alan bir yapıda olsun. Cihaz içerisinde bulunacak sensörlerimiz bizlere bu dataları 15 saniyede bir ve toplamda 100 kere göndersin.
Oluşturulan Okuma ve Yazma API Key Yöneticisi sayfasından görülebilir.
Python ile JSON Veri Gönderme¶
Python ile IOT sunucularına veri göndermek için kullanacağımız API ENDPOINT adresi https://iothook.com/api/update/ dir. Veri göndermek için yazma api_key bilgisine ihtiyaç vardır. Bu KEY e cihaz detail sayfasından ulaşabilirsiniz.
Veri göndermek için olmazsa olmaz 2 alan vardır. Bunlar api_key ve field_1 alanlarıdır. APIKEY cihaz sahipliğinizi onaylar ve en az bir veri alanı olması gerektiğinden field_1 kesinlikle olmalıdır. Diğer alanlar tanımlanmış bile olsalar gönderilmedikleri zaman None olarak işaretlenir.
Veri başarılı bir şekilde gönderildiğinde veriye dair Json REST çıktı gelmelidir. Bunu response.json() metodu ile gerçekleştiriyoruz. Örnek çıktı:
>>> {'device': 17, 'field_1': '6', 'field_2': '3.49', 'field_3': None, 'field_4': None, 'field_5': None, 'field_6': None, 'field_7': None, 'field_8': None, 'id': 502491, 'pub_date': '2019-08-31T01:07:29.438160', 'remote_address': '88.242.135.167&python-requests/2.18.4&HTTP/1.1'}
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Python ile Json Post Örneği:

# -*- coding: utf-8 -*-
"""
Python ile IOThook REST Api Testi
Kod çalıştırıldığında APIKEY ile doğrulama gerçekleştirilir.
Cihaz api_key ile ilgili veriler IOThook a post edilir.
Bu ornek IotHook servisine veri almak/gondermek icin baslangic seviyesinde
testlerin yapilmasini amaclamaktadir.
20 Eylul 2017
Güncelleme : 19 Agustos 2019
Sahin MERSIN
Daha fazlasi icin
http://www.iothook.com
ve
https://github.com/electrocoder/IOThook
sitelerine gidiniz.
Sorular ve destek talepleri icin
https://github.com/electrocoder/IOThook/issues
sayfasindan veya Meşe Bilişim den yardım alabilirsiniz.
Yayin : http://mesebilisim.com
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://www.apache.org/licenses/
"""
import json
import pprint
import random
import time
import requests
headers = {'Content-type': 'application/json'}
url = 'http://iothook.com/api/update/'
for i in range(100):
data = { # write api key
'api_key': '78b0ca6a4a7da7e20f689818', # demo hesap #17 random test
'field_1': random.randint(1, 10),
'field_2': round(random.uniform(0.0, 10.0), 2),
}
data_json = json.dumps(data)
response = requests.post(url, data=data_json, headers=headers)
pprint.pprint(response.json())
time.sleep(15)
Python ile Json Post Örneği 2:

# -*- coding: utf-8 -*-
"""
Python ile IOThook REST Api Testi
Kod çalıştırıldığında APIKEY ile doğrulama gerçekleştirilir.
Cihaz api_key ile ilgili veriler IOThook a post edilir.
Bu ornek IotHook servisine veri almak/gondermek icin baslangic seviyesinde
testlerin yapilmasini amaclamaktadir.
20 Eylul 2017
Güncelleme : 19 Agustos 2019
Sahin MERSIN
Daha fazlasi icin
http://www.iothook.com
ve
https://github.com/electrocoder/IOThook
sitelerine gidiniz.
Sorular ve destek talepleri icin
https://github.com/electrocoder/IOThook/issues
sayfasindan veya Meşe Bilişim den yardım alabilirsiniz.
Yayin : http://mesebilisim.com
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://www.apache.org/licenses/
"""
import json
import pprint
import random
import time
import requests
headers = {'Content-type': 'application/json'}
url = 'https://iothook.com/api/update/'
for i in range(100):
data = { # write api key
'api_key': 'd88f4aa6b089478f78a9c9e5', # demo hesap #24 Temperature sensor
'field_1': random.randint(1, 10),
'field_2': round(random.uniform(0.0, 10.0), 2),
}
data_json = json.dumps(data)
response = requests.post(url, data=data_json, headers=headers)
pprint.pprint(response.json())
time.sleep(10)
Python GET Metodu ile Veri Gönderme¶
IOThook Api güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Python ile Get Metodu Kullanarak Veri Gönderme Örneği:

# -*- coding: utf-8 -*-
"""
Python ile IOThook REST Api Testi
Kod çalıştırıldığında APIKEY ile doğrulama gerçekleştirilir.
Cihaz api_key ile ilgili veriler IOThook a post edilir.
Bu ornek IotHook servisine veri almak/gondermek icin baslangic seviyesinde
testlerin yapilmasini amaclamaktadir.
11 Eylul 2017
Güncelleme : 19 Agustos 2019
Sahin MERSIN
Daha fazlasi icin
http://www.iothook.com
ve
https://github.com/electrocoder/IOThook
sitelerine gidiniz.
Sorular ve destek talepleri icin
https://github.com/electrocoder/IOThook/issues
sayfasindan veya Meşe Bilişim den yardım alabilirsiniz.
Yayin : http://mesebilisim.com
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://www.apache.org/licenses/
"""
import pprint
import random
import time
import requests
for i in range(100): # write api key
url = 'http://iothook.com/api/update/?api_key=78b0ca6a4a7da7e20f689818&field_1={}&field_2={}'.format(
random.randint(1, 100), round(random.uniform(0.0, 10.0), 2))
response = requests.get(url)
pprint.pprint(response.json())
time.sleep(15)
Arduino, ESP8266 POST Metodu ile Veri Gönderme¶
Bu örnekde Arduino Uno ya RX ve TX ile bağlanmış olan ESP8266 ile iothook a veri gonderme örneği verilmiştir. Örnekde 0-100 arasında rastgele sayı üretilerek iothook da #19 test id numaralı cihaz için gönderim gerçekleşmiştir. Cihaz datalarını https://iothook.com/en/device/data/19/ linkinden gercek zamanlı olarak takip edebilirsiniz.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
/*
Arduino ile ESP8266 Wifi Modul Testi
Kod Arduino ya yuklendiginde Arduino IDE nin Serial Monitor u
ile ESP8266 arasinda haberlesme gozlenebilir.
Arduino ile ESP8266 arasindaki iletisim Baud ayari
115200 olmalidir.
Arduino 0 ile 100 arasinda uretmis oldugu Random sayıyı iothook a gonderir.
Bu cihaza ait datalar
https://iothook.com/en/device/data/19/
adresinden gercek zamanli olarak izlenebilir.
Bu ornek IOThook servisine veri gondermek icin baslangic ayarlarinin
yapilmasini amaclamaktadir.
24 Eylul 2017
Güncelleme : 19 Agustos 2019
Sahin MERSIN
Daha fazlasi icin
http://www.iothook.com
ve
https://github.com/electrocoder/IOThook
sitelerine gidiniz.
Sorular ve destek talepleri icin
https://github.com/electrocoder/IOThook/issues
sayfasina gidiniz.
Yayin ve sahiplik http://mesebilisim.com
*/
#include "SoftwareSerial.h"
String ssid = "WIFI_ID";
String password = "WIFI_PASSWORD";
SoftwareSerial esp(10, 11);// RX, TX
String data;
String server = "iothook.com";
String uri = "/api/update/";
void setup() {
esp.begin(115200);
Serial.begin(115200);
Serial.println("Arduino ile ESP8266 Wifi Modul Testi");
Serial.println(" www.IOThook.com ");
Serial.println("");
reset();
connectWifi();
}
void reset() {
esp.println("AT+RST");
delay(2000);
if (esp.find("OK") ) Serial.println("Modul Reset yapildi");
else Serial.println("Module Reset yapılamadi");
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if (esp.find("OK")) {
Serial.println("ESP8266 Wifi ye baglandi");
}
else {
connectWifi();
Serial.println("ESP8266 Wifi ye baglanamadı!");
}
}
void loop () {
data = "{\"api_key\":\"58088bb005633bb39cdf3b7d\",\"field_1\":" + String(random(0, 100)) + "}";
httppost();
delay(5000);
}
void httppost () {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");
if ( esp.find("OK")) {
Serial.println("TCP baglanti hazir");
}
else
Serial.println("TCP baglanti hatali");
delay(3000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
esp.println(postRequest.length() );
delay(1500);
if (esp.find(">")) {
Serial.println("Gonderiliyor...");
esp.print(postRequest);
if ( esp.find("SEND OK")) {
Serial.println("Gonderildi :)");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
esp.println("AT+CIPCLOSE");
}
else
Serial.println("Gonderilemedi :(");
}
else
Serial.println("Gonderim hatasi! ESP hazir degil!");
}
Arduino, ESP8266 POST Metodu ile 2 Veri Gönderme¶
Bu örnekde Arduino Uno ya RX ve TX ile bağlanmış olan ESP8266 ile iothook a veri gonderme örneği verilmiştir. Örnekde 0-100 arasında rastgele 2 sayı üretilerek iothook da #12 temp id numaralı cihaz için gönderim gerçekleşmiştir. Cihaz datalarını https://iothook.com/en/device/data/12/ linkinden gercek zamanlı olarak takip edebilirsiniz.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
/*
Arduino ile ESP8266 Wifi Modul Testi
Kod Arduino ya yuklendiginde Arduino IDE nin Serial Monitor u
ile ESP8266 arasinda haberlesme gozlenebilir.
Arduino ile ESP8266 arasindaki iletisim Baud ayari
115200 olmalidir.
Arduino 0 ile 100 arasinda uretmis oldugu 2 adet Random sayıyı iothook a gonderir.
Bu sayılar 'data' değişkeni içerisinde field_1 ve field_2 değerleridir. Bu değerler
sensör olarak kullanılmaktadır. Sıcaklık ve Nem gibi sensörlerinizi bu alanlara
gönderebilirsiniz.
Bu cihaza ait datalar
https://iothook.com/en/device/data/12/
adresinden gercek zamanli olarak izlenebilir.
Bu ornek IOThook servisine veri gondermek icin baslangic ayarlarinin
yapilmasini amaclamaktadir.
24 Eylul 2017
Sahin MERSIN
Daha fazlasi icin
http://www.iothook.com
ve
https://github.com/electrocoder/IOThook
sitelerine gidiniz.
Sorular ve destek talepleri icin
https://github.com/electrocoder/IOThook/issues
sayfasina gidiniz.
Yayin ve sahiplik http://mesebilisim.com
*/
#include "SoftwareSerial.h"
String ssid = "WIFI_SSID";
String password = "WIFI_PASSWORD";
SoftwareSerial esp(10, 11);// RX, TX
String data;
String server = "iothook.com";
String uri = "/api/update/";
void setup() {
esp.begin(115200);
Serial.begin(115200);
Serial.println("Arduino ile ESP8266 Wifi Modul Testi");
Serial.println(" www.IOThook.com ");
Serial.println("");
reset();
connectWifi();
}
void reset() {
esp.println("AT+RST");
delay(2000);
if (esp.find("OK") ) Serial.println("Modul Reset yapildi");
else Serial.println("Module Reset yapılamadi");
}
void connectWifi() {
String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
esp.println(cmd);
delay(4000);
if (esp.find("OK")) {
Serial.println("ESP8266 Wifi ye baglandi");
}
else {
connectWifi();
Serial.println("ESP8266 Wifi ye baglanamadı!");
}
}
void loop () {
data = "{\"api_key\":\"58088bb005633bb39cdf3b7d\",\"field_1\":" + String(random(0, 100)) + ",\"field_2\":" + String(random(0, 100)) + "}";
httppost();
delay(8000);
}
void httppost () {
esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");
if ( esp.find("OK")) {
Serial.println("TCP baglanti hazir");
}
else
Serial.println("TCP baglanti hatali");
delay(3000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";
esp.print(sendCmd);
esp.println(postRequest.length() );
delay(1500);
if (esp.find(">")) {
Serial.println("Gonderiliyor...");
esp.print(postRequest);
if ( esp.find("SEND OK")) {
Serial.println("Gonderildi :)");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
esp.println("AT+CIPCLOSE");
}
else
Serial.println("Gonderilemedi :(");
}
else
Serial.println("Gonderim hatasi! ESP hazir degil!");
}
Arduino, ESP8266, Nodemcu GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde Arduino, ESP8266 ve NodeMCU ile ile Get metodu kullanarak veri gönderme örneği verilmiştir:
// 18.09.2017
// Guncelleme : 19.08.2019
// nodemcu ile sicaklik ve nem takibi
// electrocoder@gmail.com
// sahin mersin
// v1
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
//for LED status
#include <Ticker.h>
#include <ESP8266HTTPClient.h>
#include "DHT.h"
#define DHTPIN 4 // what digital pin we're connected to // D2 - GPIO4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Ticker ticker;
void tick()
{
//toggle state
int state = digitalRead(BUILTIN_LED); // get the current state of GPIO1 pin
digitalWrite(BUILTIN_LED, !state); // set pin to the opposite state
}
//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) {
Serial.println("Entered config mode");
Serial.println(WiFi.softAPIP());
//if you used auto generated SSID, print it
Serial.println(myWiFiManager->getConfigPortalSSID());
//entered config mode, make led toggle faster
ticker.attach(0.2, tick);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//set led pin as output
pinMode(BUILTIN_LED, OUTPUT);
// start ticker with 0.5 because we start in AP mode and try to connect
ticker.attach(0.6, tick);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager;
//reset settings - for testing
//wifiManager.resetSettings();
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
wifiManager.setAPCallback(configModeCallback);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
if (!wifiManager.autoConnect("MeseIoT", "MeseIoT**")) {
Serial.println("failed to connect and hit timeout");
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(1000);
}
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
ticker.detach();
//keep LED on
digitalWrite(BUILTIN_LED, LOW);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
///
HTTPClient http;
// configure server and url
http.begin("http://iothook.com/api/update/?api_key=58088bb005633bb39cdf3b7d&field_1=" + String(t) + "&field_2=" + String(h) + "");
//http.begin("192.168.1.12", 80, "/test.html");
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK) {
// get lenght of document (is -1 when Server sends no Content-Length header)
int len = http.getSize();
// create buffer for read
uint8_t buff[128] = { 0 };
// get tcp stream
WiFiClient * stream = http.getStreamPtr();
// read all data from server
while (http.connected() && (len > 0 || len == -1)) {
// get available data size
size_t size = stream->available();
if (size) {
// read up to 128 byte
int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));
// write it to Serial
Serial.write(buff, c);
if (len > 0) {
len -= c;
}
}
delay(1);
}
Serial.println();
Serial.print("[HTTP] connection closed or file end.\n");
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
////
delay(13000);
}
GO GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde GO dili ile ile Get metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "http://iothook.com/api/update?api_key=58088bb005633bb39cdf3b7d&field_1=10&field_2=2&field_3=3"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}
PHP GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde PHP dili ile ile Get metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
<?php
$request = new HttpRequest();
$request->setUrl('http://iothook.com/api/update');
$request->setMethod(HTTP_METH_GET);
$request->setQueryData(array(
'api_key' => '58088bb005633bb39cdf3b7d',
'field_1' => '10',
'field_2' => '2',
'field_3' => '3'
));
$request->setHeaders(array(
'postman-token' => '791ba738-7cb8-a920-0e5c-883cfb3e4498',
'cache-control' => 'no-cache'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
NodeJS GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde NodeJS Native metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
var http = require("http");
var options = {
"method": "GET",
"hostname": "iothook.com",
"port": null,
"path": "/api/update?api_key=58088bb005633bb39cdf3b7d&field_1=10&field_2=2&field_3=3",
"headers": {
"cache-control": "no-cache",
"postman-token": "033da3c8-6196-cd49-f72d-1850a7d18500"
}
};
var req = http.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
Javascript Jquery Ajax GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde NodeJS Native metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
var settings = {
"async": true,
"crossDomain": true,
"url": "http://iothook.com/api/update?api_key=58088bb005633bb39cdf3b7d&field_1=10&field_2=2&field_3=3",
"method": "GET",
"headers": {
"cache-control": "no-cache",
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
Java Unirest GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde NodeJS Native metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
HttpResponse<String> response = Unirest.get("http://iothook.com/api/update?api_key=58088bb005633bb39cdf3b7d&field_1=10&field_2=2&field_3=3")
.header("cache-control", "no-cache")
.asString();
Java Unirest GET Metodu ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde NodeJS Native metodu kullanarak veri gönderme örneği verilmiştir:
// 04 Eylul 2017
// Guncelleme: 19 Agustos 2019
// Sahin MERSIN
// iothook.com
// postman kullanilarak olusturulmustur
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://iothook.com/api/update?api_key=58088bb005633bb39cdf3b7d&field_1=10&field_2=2&field_3=3")
.get()
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
Arduino Ethernet Shield HTTP GET ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde Arduino Ethernet Shield kullanarak veri gönderme örneği verilmiştir:
/*
Server Odasi Sicaklik ve Nem Takibi
electrocoder@gmail.com
sahin@mesebilisim.com
mesebilisim.com
13.01.2020
*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
EthernetClient client;
char server[] = "iothook.com";
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 20 * 1000;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1);
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
Ethernet.begin(mac, ip, myDns);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
delay(1000);
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.write(c);
}
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
void httpRequest() {
client.stop();
if (client.connect(server, 80)) {
Serial.println("connecting...");
client.println("GET /api/update/?api_key=1c623cec18681&field_1=0&field_2=0 HTTP/1.1");
client.println("Host: www.iothook.com");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else {
Serial.println("connection failed");
}
}
Arduino Ethernet Shield Wiznet W5100 HTTP GET ile Veri Gönderme¶
IOThook Api v1.4 güncellemesi ile GET metodu ile veri göndermeye izin vermektedir.
Bu örneğe ve diğerlerine IOTHOOK Git sayfasından ulaşabilirsiniz.
Bu örnekde Arduino Ethernet Shield kullanarak veri gönderme örneği verilmiştir:
/*
3 Adet Random Veri Gonderme
electrocoder@gmail.com
sahin@mesebilisim.com
mesebilisim.com
19.11.2021
*/
#include <SPI.h>
#include <Ethernet.h>
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
// initialize the library instance:
EthernetClient client;
char server[] = "iothook.com"; // also change the Host line in httpRequest()
//IPAddress server(64,131,82,241);
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// start serial port:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
}
void loop() {
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.write(c);
}
// if ten seconds have passed since your last connection,
// then connect again and send data:
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server:
void httpRequest() {
// close any connection before send a new request.
// This will free the socket on the WiFi shield
client.stop();
// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP GET request:
int i = random(0, 100);
int j = random(0, 100);
int k = random(0, 100);
client.print("GET /api/update/?api_key=caea43edff58fecd8c07e3db");
client.print("&field_1=");
client.print(String(i));
client.print("&field_2=");
client.print(String(j));
client.print("&field_3=");
client.print(String(k));
client.println(" HTTP/1.1");
client.println("Host: iothook.com");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
lastConnectionTime = millis();
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}
}