Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pxsty0 committed Dec 31, 2023
1 parent b8dde09 commit 81d3f6d
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 18 deletions.
12 changes: 8 additions & 4 deletions examples/DataSend/DataSend.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <WiFi.h>
#include <PxServ.h>

PxServ db;
PxServ pxserv;

#define WIFI_SSID "" // Wifi Adı
#define WIFI_PASS "" // Wifi Şifresi
Expand All @@ -16,16 +16,20 @@ void setup()
Serial.print(".");
}
Serial.println("Baglandi");
db.login(""); // APIKEY
pxserv.login(""); // PxServ API Key
}

void loop()
{

db.set("msg", "Hello World");
int status1 = pxserv.set("msg", "Hello Earth");

String msg = db.get("msg");
String msg = pxserv.get("msg");

int status2 = pxserv.del("msg");

Serial.println("Status 1 : " + String(status1));
Serial.println("Status 2 : " + String(status2));
Serial.println("Mesaj : " + String(msg));

delay(1000);
Expand Down
3 changes: 1 addition & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name=PxServ
version=1.0.0
version=1.0.1
author=mustafa_kok
maintainer=PxServ <mustafa_kok>
sentence=Thanks to PxServ, get the opportunity to add power to IoT projects that need things like sending data and reading data over WiFi!
paragraph=Thanks to PxServ, get the opportunity to add power to IoT projects that need things like sending data and reading data over WiFi!
category=*
url=https://github.com/pxsty0/pxserv.lib
architectures=*
depends=ArduinoJson
132 changes: 121 additions & 11 deletions src/PxServ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int PxServ::set(String key, String value)
HTTPClient https;

String token = PxServ::token;
if (https.begin(*client, "http://api.pxserv.net/api/plain/set"))
if (https.begin(*client, "https://api.pxserv.net/api/plain/set"))
{
https.addHeader("Content-Type", "application/json");

Expand All @@ -28,8 +28,27 @@ int PxServ::set(String key, String value)
httpCode == HTTP_CODE_MOVED_PERMANENTLY ||
httpCode == HTTP_CODE_NO_CONTENT)
{
String payload = https.getString();
if (payload.startsWith("PXSERV+ERR="))
{
payload.replace("PXSERV+ERR=", "");
String errCode = payload;

status = 200;
if (errCode == "INVALID_AUTH")
status = 401;
else if (errCode == "INVALID_PARAMS")
status = 204;
}
else if (payload.startsWith("PXSERV+DATA="))
{
payload.replace("PXSERV+DATA=", "");
String dataCode = payload;

if (dataCode == "OK")
status = 200;
}
else
status = 400;
}
else
{
Expand All @@ -44,22 +63,23 @@ int PxServ::set(String key, String value)
}
else
{
status = 2;
status = 1;
}
}
else
{
status = 3;
status = 1;
}
delete client;
return status;
}
String PxServ::get(String key)
{

WiFiClientSecure *client = new WiFiClientSecure;

int status = 200;
String data = "!";
String data = "PXSERV+DATA=NOT_READING";

if (client)
{
Expand All @@ -68,7 +88,7 @@ String PxServ::get(String key)
HTTPClient https;

String token = PxServ::token;
if (https.begin(*client, "https://cdn.anicordapp.net/api/plain/get"))
if (https.begin(*client, "https://api.pxserv.net/api/plain/get"))
{
https.addHeader("Content-Type", "application/json");

Expand All @@ -80,8 +100,28 @@ String PxServ::get(String key)
httpCode == HTTP_CODE_MOVED_PERMANENTLY ||
httpCode == HTTP_CODE_NO_CONTENT)
{
data = https.getString();
status = 200;
String payload = https.getString();
if (payload.startsWith("PXSERV+ERR="))
{
payload.replace("PXSERV+ERR=", "");
String errCode = payload;

if (errCode == "INVALID_AUTH")
status = 401;
else if (errCode == "INVALID_PARAMS")
status = 204;
else if (errCode == "INVALID_DATA_KEY")
status = 206;
}
else if (payload.startsWith("PXSERV+DATA="))
{
payload.replace("PXSERV+DATA=", "");
data = payload;

status = 200;
}
else
status = 400;
}
else
{
Expand All @@ -96,14 +136,84 @@ String PxServ::get(String key)
}
else
{
status = 2;
status = 1;
}
}
else
{
status = 3;
status = 1;
}
delete client;
return data;
}
int PxServ::del(String key){};
int PxServ::del(String key)
{

WiFiClientSecure *client = new WiFiClientSecure;
int status = 200;
if (client)
{
client->setInsecure();

HTTPClient https;

String token = PxServ::token;
if (https.begin(*client, "https://api.pxserv.net/api/plain/delete"))
{
https.addHeader("Content-Type", "application/json");

int httpCode = https.POST("{\"token\":\"" + token +
"\",\"key\":\"" + key + "\"}");
if (httpCode > 0)
{
if (httpCode == HTTP_CODE_OK ||
httpCode == HTTP_CODE_MOVED_PERMANENTLY ||
httpCode == HTTP_CODE_NO_CONTENT)
{
String payload = https.getString();
if (payload.startsWith("PXSERV+ERR="))
{
payload.replace("PXSERV+ERR=", "");
String errCode = payload;

if (errCode == "INVALID_AUTH")
status = 401;
else if (errCode == "INVALID_PARAMS")
status = 204;
else if (errCode == "INVALID_DATA_KEY")
status = 206;
}
else if (payload.startsWith("PXSERV+DATA="))
{
payload.replace("PXSERV+DATA=", "");
String dataCode = payload;

if (dataCode == "OK")
status = 200;
}
else
status = 400;
}
else
{
status = 1;
}
https.end();
}
else
{
status = 1;
}
}
else
{
status = 1;
}
}
else
{
status = 1;
}
delete client;
return status;
};
2 changes: 1 addition & 1 deletion src/PxServ.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <WiFiMulti.h>
#include <HTTPClient.h>
#else
#warning "Kütüphane Sadece Deneyap Kartlar İle Çalışmaktadır"
#warning "Kütüphane Sadece Deneyap Geliştirme Kartları ve ESP32 ler ile Çalışmaktadır"
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
Expand Down

0 comments on commit 81d3f6d

Please sign in to comment.