Skip to content

Commit

Permalink
add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeoooo committed Jan 29, 2024
1 parent f57500e commit 2896280
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pocketbasearduino.ino
pb_data
pb_migrations
pocketbase.exe
examples
CHANGELOG.md
LICENSE.md
pocketbase_0.20.5_windows_amd64.zip
57 changes: 57 additions & 0 deletions examples/example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "PocketBaseArduino.h"

// ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// FOR ESP32
// #include <HTTPClient.h>
// #include <WiFi.h>
// #include <WiFiClientSecure.h>

// HTTPS REQUESTS
#include <BearSSLHelpers.h>

const char *ssid = "YOUR_SSID";
const char *password = "YOUR_PASSWORD";

// Initializing the Pocketbase instance
PocketbaseArduino pb("YOUR_POCKETBASE_BASE_URL");
String record;

void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println("Connecting to WiFi...");
}

// Example usage of getOne() function
// getOne("record_id", "expand", "fields"),
// if expand or fields are empty place nullptr
record = pb.collection("collection_name").getOne("record_id", "expand", "fields");

// Example usage of getList() function
// getList("page", "perPage", "sort", "filter", "skipTotal", "expand", "fields"),
// if expand or fields are empty place nullptr
record = pb.collection("collection_name").getList("page", "perPage", "sort", "filter", "skipTotal", "expand", "fields");

// Example usage of deleteRecord function
// deleteRecord("record_id");
record = pb.collection("collection_name").deleteRecord("record_id");

// printing data
Serial.println(record);
}

void loop()
{
// Fetches and prints data from the 'notes' collection every 5 seconds
record = pb.collection("collection_name").getList("page", "perPage", "sort", "filter", "skipTotal", "expand", "fields");
Serial.println("Data from 'notes' collection:\n" + record);
delay(5000);
}

0 comments on commit 2896280

Please sign in to comment.