Skip to content

Commit 7def896

Browse files
authored
Merge branch 'pxsty0:main' into main
2 parents 8636bb4 + 871cbbd commit 7def896

File tree

5 files changed

+90
-11
lines changed

5 files changed

+90
-11
lines changed

examples/helloWorld/helloWorld.ino

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void setup()
1212

1313
void loop()
1414
{
15-
// Add data
16-
PxServ::Callback setResult = client.setData("msg", "value"); // Add "value" to the "msg" key
15+
// Save data
16+
PxServ::Callback setResult = client.setData("exampleData1", "value"); // Add "value" to the "exampleData1" key
1717
Serial.print("Set Result -> Status: ");
1818
Serial.print(setResult.status);
1919
Serial.print(" | Message: ");
@@ -23,8 +23,19 @@ void loop()
2323

2424
delay(2000); // Wait for two seconds
2525

26+
// Toggle data
27+
PxServ::Callback toggleResult = client.toggleData("exampleData2"); // Toggles the value of the “exampleData2” key between 0 and 1
28+
Serial.print("Toggle Result -> Status: ");
29+
Serial.print(toggleResult.status);
30+
Serial.print(" | Message: ");
31+
Serial.print(toggleResult.message);
32+
Serial.print(" | Data: ");
33+
Serial.println(toggleResult.data);
34+
35+
delay(2000); // Wait for two seconds
36+
2637
// Get data
27-
PxServ::Callback getResult = client.getData("msg"); // Get the value for the "msg" key
38+
PxServ::Callback getResult = client.getData("exampleData1"); // Get the value for the "exampleData1" key
2839
Serial.print("Get Result -> Status: ");
2940
Serial.print(getResult.status);
3041
Serial.print(" | Message: ");
@@ -35,7 +46,7 @@ void loop()
3546
delay(2000); // Wait for two seconds
3647

3748
// Remove data
38-
PxServ::Callback removeResult = client.removeData("msg"); // Remove the "msg" key
49+
PxServ::Callback removeResult = client.removeData("exampleData1"); // Remove the "exampleData" key
3950
Serial.print("Remove Result -> Status: ");
4051
Serial.print(removeResult.status);
4152
Serial.print(" | Message: ");

examples/merhabaDunya/merhabaDunya.ino

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void setup()
1212

1313
void loop()
1414
{
15-
// Veri Yazdırma
16-
PxServ::Callback setResult = client.setData("msg", "value"); // "msg" anahtarına "value" değerini ekle
15+
// Veri Kaydetme
16+
PxServ::Callback setResult = client.setData("exampleData1", "value"); // "exampleData1" anahtarına "value" değerini ekle
1717
Serial.print("Veri Ekleme Sonucu -> Durum: ");
1818
Serial.print(setResult.status);
1919
Serial.print(" | Mesaj: ");
@@ -23,8 +23,19 @@ void loop()
2323

2424
delay(2000); // İki saniye bekle
2525

26+
// Veri Geçişi
27+
PxServ::Callback toggleResult = client.toggleData("exampleData2"); // “exampleData2” anahtarının değerini 0 ile 1 arasında geçiş yaptırır
28+
Serial.print("Toggle Result -> Status: ");
29+
Serial.print(toggleResult.status);
30+
Serial.print(" | Message: ");
31+
Serial.print(toggleResult.message);
32+
Serial.print(" | Data: ");
33+
Serial.println(toggleResult.data);
34+
35+
delay(2000); // İki saniye bekle
36+
2637
// Veri Okuma
27-
PxServ::Callback getResult = client.getData("msg"); // "msg" anahtarının değerini getir
38+
PxServ::Callback getResult = client.getData("exampleData1"); // "exampleData1" anahtarının değerini getir
2839
Serial.print("Veri Okuma Sonucu -> Durum: ");
2940
Serial.print(getResult.status);
3041
Serial.print(" | Mesaj: ");
@@ -35,7 +46,7 @@ void loop()
3546
delay(2000); // İki saniye bekle
3647

3748
// Veri Kaldırma
38-
PxServ::Callback removeResult = client.removeData("msg"); // "msg" anahtarını kaldır
49+
PxServ::Callback removeResult = client.removeData("exampleData1"); // "exampleData1" anahtarını kaldır
3950
Serial.print("Kaldırma Sonucu -> Durum: ");
4051
Serial.print(removeResult.status);
4152
Serial.print(" | Mesaj: ");

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=PxServ
2-
version=1.0.8
2+
version=1.1.0
33
author=mustafa_kok
44
maintainer=PxServ
55
sentence=PxServ Library for ESP32 / ESP8266
66
paragraph=Enhance your IoT projects with PxServ by enabling data transmission and retrieval over WiFi!
77
category=*
8-
url=https://github.com/pxserv/pxserv.arduino
8+
url=https://docs.pxserv.net/tr/arduino-kutuphanesi
99
architectures=*
1010
depends=Arduino_JSON

src/PxServ.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,63 @@ PxServ::Callback PxServ::setData(String key, String value)
3838
https.addHeader("Content-Type", "application/json");
3939
https.addHeader("apikey", _apiKey);
4040

41-
int httpCode = https.POST("{\"key\":\"" + key + "\",\"value\":\"" + value + "\"}");
41+
JSONVar body;
42+
body["key"] = key;
43+
body["value"] = value;
44+
45+
int httpCode = https.POST(JSON.stringify(body));
46+
if (httpCode > 0)
47+
{
48+
String payload = https.getString();
49+
JSONVar result = JSON.parse(payload);
50+
51+
if (JSON.typeof(result) != "object")
52+
{
53+
callback.status = 400;
54+
callback.message = "Response format not appropriate";
55+
}
56+
else
57+
{
58+
int status = result["status"];
59+
String message = result["message"];
60+
61+
callback.status = status;
62+
callback.message = message;
63+
}
64+
65+
https.end();
66+
}
67+
}
68+
}
69+
70+
delete client;
71+
return callback;
72+
}
73+
74+
PxServ::Callback PxServ::toggleData(String key)
75+
{
76+
WiFiClientSecure *client = new WiFiClientSecure;
77+
Callback callback;
78+
79+
callback.status = -1;
80+
callback.message = "failed to send request";
81+
callback.data = "";
82+
83+
if (client)
84+
{
85+
client->setInsecure();
86+
87+
HTTPClient https;
88+
89+
if (https.begin(*client, "https://api.pxserv.net/database/toggleData"))
90+
{
91+
https.addHeader("Content-Type", "application/json");
92+
https.addHeader("apikey", _apiKey);
93+
94+
JSONVar body;
95+
body["key"] = key;
96+
97+
int httpCode = https.POST(JSON.stringify(body));
4298
if (httpCode > 0)
4399
{
44100
String payload = https.getString();

src/PxServ.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class PxServ
2828
PxServ(String apiKey);
2929
static void connectWifi(String ssid, String password);
3030
Callback setData(String key, String value);
31+
Callback toggleData(String key);
3132
Callback getData(String key);
3233
Callback removeData(String key);
3334

0 commit comments

Comments
 (0)