Skip to content

Commit 5fc19f1

Browse files
committed
Create Get_Methods_Json.ino
1 parent bd8c1b2 commit 5fc19f1

File tree

6 files changed

+205
-0
lines changed

6 files changed

+205
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//Wifi Kütüphanesi ve Http istek Kütüphanesi
2+
#include<ESP8266WiFi.h>
3+
#include <ESP8266HTTPClient.h>
4+
//Json Kütüphanesi
5+
#include<ArduinoJson.h>
6+
7+
8+
StaticJsonBuffer<200> jsonBuffer;
9+
//wifi ismi ve şifre
10+
const char* ssid="TTNET_HUAWEI_9207";
11+
const char* password ="80D75FD3A8";
12+
13+
14+
void setup() {
15+
// put your setup code here, to run once:
16+
//serial haberleşme
17+
Serial.begin(115200);
18+
//wifi bağlantısı
19+
WiFi.begin(ssid,password);
20+
21+
// wifi ye Bağlanıyor iken
22+
while(WiFi.status()!=WL_CONNECTED){
23+
24+
delay(1000);
25+
Serial.println("Bağlanıyor...");
26+
}
27+
28+
// eğer wifiye bağlanmış şse
29+
if(WiFi.status()==WL_CONNECTED){
30+
31+
//http kütüphanesinden
32+
HTTPClient http;
33+
//ilgili url e istek at
34+
http.begin("http://jsonplaceholder.typicode.com/posts/1");
35+
//atılan istek kodu
36+
int httpCode=http.GET();
37+
//başarılı ise
38+
if(httpCode==200){
39+
// içinde ki tüm değerleri string e ata
40+
String body=http.getString();
41+
Serial.println(body);
42+
//ve json objesine aktar parçalatmak için
43+
JsonObject& jsonparse=jsonBuffer.parseObject(body);
44+
45+
//gelen json verisinde ki title keyinni title a ata
46+
const char* title= jsonparse["title"];
47+
//ve serial ekrana yazdır
48+
Serial.printf("VErimiz : %s",title);
49+
50+
}
51+
//tüm işlemler sonrasında http isteğini kes
52+
http.end();
53+
}else{
54+
//herhangi bir hata olursa ekranda göster
55+
Serial.println("Bağlantı hatası");
56+
}
57+
58+
}
59+
60+
void loop() {
61+
//sonsuz döngü
62+
63+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
#include<ESP8266WiFi.h>
3+
#include <ESP8266HTTPClient.h>
4+
5+
const char* ssid="TTNET_HUAWEI_9207";
6+
const char* password ="80D75FD3A8";
7+
8+
void setup() {
9+
10+
Serial.begin(115200);
11+
WiFi.begin(ssid,password);
12+
13+
while(WiFi.status()!=WL_CONNECTED){
14+
15+
delay(1000);
16+
Serial.println("Bağlanıyor...");
17+
}
18+
19+
}
20+
21+
void loop() {
22+
23+
if(WiFi.status()==WL_CONNECTED){
24+
Serial.println("İçerideyiz");
25+
HTTPClient http;
26+
27+
http.begin("http://jsonplaceholder.typicode.com/posts/1");
28+
int httpCode=http.GET();
29+
30+
Serial.println(httpCode);
31+
if(httpCode>0){
32+
String body=http.getString();
33+
Serial.println(body);
34+
}
35+
36+
http.end();
37+
}
38+
delay(3000);
39+
40+
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//json verisi olusturmak iöçinü
2+
3+
//json kütüphanesi
4+
#include<ArduinoJson.h>
5+
6+
StaticJsonBuffer<200> jsonBuffer;
7+
8+
void setup() {
9+
// put your setup code here, to run once:
10+
//seri haberleşme
11+
Serial.begin(115200);
12+
13+
// json objesi oluşturma kütüphanesi
14+
JsonObject& jsoncreate=jsonBuffer.createObject();
15+
16+
//keyi adin ve soyad olan bir json olustur
17+
jsoncreate["adin"]="harunlakodla";
18+
jsoncreate["soyad"]="Kurt";
19+
20+
//data altında bir array olusturmak istersek
21+
JsonArray& data =jsoncreate.createNestedArray("data");
22+
23+
data.add(44);
24+
data.add("Merhaba Nasılsın");
25+
26+
27+
//jsoncreate.printTo(Serial);
28+
// json verisini serial ekranda basmak istersek
29+
jsoncreate.prettyPrintTo(Serial);
30+
31+
}
32+
33+
void loop() {
34+
// put your main code here, to run repeatedly:
35+
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
bu örnek json parçalamak işlemi içindir
3+
*/
4+
5+
// json kütüphanesi
6+
#include<ArduinoJson.h>
7+
8+
9+
StaticJsonBuffer<200> jsonBuffer;
10+
//json verimiz
11+
char json[]="{adin:haurnlakodla,soyad:kurt,il:kocaeli}";
12+
void setup(){
13+
//seri haberleşme
14+
Serial.begin(115200);
15+
}
16+
17+
18+
void loop(){
19+
//json u parçalamak için
20+
JsonObject& jsonparse=jsonBuffer.parseObject(json);
21+
// her bir keyden verilerimizi alıyoruz
22+
const char* adin= jsonparse["adin"];
23+
const char* soyad= jsonparse["soyad"];
24+
const char* il= jsonparse["il"];
25+
// her birini ekrana basıyoruz
26+
Serial.println(adin);
27+
Serial.println(soyad);
28+
Serial.println(il);
29+
30+
delay(1000);
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from flask import Flask,request,jsonify
2+
3+
""" Flask ı başlatmak için app e atıyoruz"""
4+
app=Flask(__name__)
5+
6+
"""app.route diyerek url üzerinde ki istekleri yakalıyoruz"""
7+
@app.route('/api',methods=['GET'])# methodumuzun ne oldugunu anlıyoruz
8+
def api():
9+
jsonolustur={} #bir list map olusturduk json için
10+
jsonolustur['APİ']=str(request.args['APİ']) #url üzerinden get işlemi ile gelen parametreler
11+
return jsonify(jsonolustur)# json olarak geri döndürüyoruz
12+
13+
#ilgili sayfa için başlatıcı
14+
if __name__ =='__main__':
15+
"""app run diyerek flask ın çalışmasını başlatıyoruz localhost ve portumuzu giriyoruz"""
16+
app.run(debug=True,host='localhost',port=9874)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from flask import jsonify,Flask
2+
3+
app=Flask(__name__)
4+
"json durumu"
5+
durum=[
6+
{'name':'Merhaba'},
7+
{'name':'Nasılsın'},
8+
{'name':'Hayat Nasıl Gidiyor'},
9+
]
10+
"ilgili url e istek atıldığında"
11+
@app.route('/',methods=['GET'])
12+
def main():
13+
"bir return işlemi olsun"
14+
return jsonify({'durum':durum})
15+
16+
if __name__ == '__main__':
17+
"hani url den erişeceğimiz..."
18+
app.run(debug=True,host='localhost',port=9875)

0 commit comments

Comments
 (0)