Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
80f690e
implemented light sleep
Adamlip1334 May 21, 2023
131bf2c
laid out groundwork for calibration
Adamlip1334 May 23, 2023
ba6637e
fixed payload parameters
Adamlip1334 May 24, 2023
792c434
added BLE callback for calibration
Adamlip1334 May 24, 2023
559dc5d
added BLE callbacks for calibration
Adamlip1334 May 24, 2023
cd98311
allows calibration from percentage value
Adamlip1334 May 31, 2023
ee5d9c1
Merge branch 'esp-now-wss' of https://github.com/Adamlip1334/LiquidPr…
Adamlip1334 May 31, 2023
4115ff3
fixed errors
Adamlip1334 Jun 7, 2023
dcaefa4
organized files
Adamlip1334 Jun 26, 2023
5c1a132
added sleep mode
Adamlip1334 Jun 26, 2023
6c5df7b
added sleep mode
Adamlip1334 Jun 28, 2023
c257e6c
added function to disable bluetooth
Adamlip1334 Jul 18, 2023
2a0e62c
allows disabling/enabling bluetooth
Adamlip1334 Jul 18, 2023
a2d32e9
enable/disable ble from liquid-prep
Adamlip1334 Jul 18, 2023
c9322ba
allows toggling bluetooth from liquid-prep
Adamlip1334 Jul 18, 2023
3c58591
removed sleep mode
Adamlip1334 Aug 16, 2023
7f922e4
removed sleep mode
Adamlip1334 Aug 16, 2023
b1054c3
removed sleep mode
Adamlip1334 Aug 16, 2023
59f9e72
added logic to change device name over bluetooth
Adamlip1334 Aug 16, 2023
850a159
Merge pull request #23 from Adamlip1334/esp-now-wss-v1
playground Aug 16, 2023
ae3bbc0
Merge branch 'develop' into esp-now-wss-v1
Aug 16, 2023
3edf1ad
Add logic to toggle bluetooth and query bluetooth status
Aug 17, 2023
3c706ae
add capacitance to data struct
Sep 22, 2023
3d4f995
Merge pull request #24 from Liquid-Prep/bluetooth-ota-no-sleep
Gaurav-Ramakrishna Oct 12, 2023
7103c10
Merge branch 'develop' into bluetooth-ota-no-sleep
Nov 8, 2023
dfb01bd
added ability to change input pin for sensor
Adamlip1334 Nov 13, 2023
1b96917
chaning input pin via gateway
Adamlip1334 Nov 16, 2023
24b4e33
Merge pull request #29 from Adamlip1334/changepin
playground Nov 17, 2023
1aa9121
Merge pull request #27 from Liquid-Prep/bluetooth-ota-no-sleep
playground Jan 9, 2024
e94b956
bring over firmwares
Adamlip1334 Jan 9, 2024
f95c801
changed calbration to platesensorr method
Adamlip1334 Jan 9, 2024
f11e1c9
changed calibration method
Adamlip1334 Jan 10, 2024
4e03bf3
cleaned up code
Adamlip1334 Jan 10, 2024
9b8f88b
Merge pull request #31 from Adamlip1334/plantmate
playground Jan 10, 2024
fef5b72
added bluetooth
Adamlip1334 Jan 11, 2024
ac3195e
Merge pull request #32 from Adamlip1334/plantmate
playground Jan 11, 2024
bf83143
set pin number
Jan 11, 2024
f81b184
resolve merge conflict
Jan 11, 2024
baeade0
correct calibration to obtain the most frequent value for air and wat…
Jan 12, 2024
77e6e84
Merge pull request #34 from Liquid-Prep/plantmate
playground May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 267 additions & 137 deletions esp-now/esp-mesh-bluetooth/src/main.cpp

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions esp-now/esp-now-gateway/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ unsigned long currentMillis = 0;

// TODO: allow input certain values in webtools and writ to SPIFFS at the time of flashing
int espInterval=90000; //espInterval for reading data
int capacitance;
String wsserver = "192.168.86.24"; //ip address of Express server
int wsport= 3000;
char path[] = "/"; //identifier of this device
Expand All @@ -35,7 +36,7 @@ String leaderMac = "7821848D8840";

void calculate() {
int val = analogRead(sensorPin); // connect sensor to Analog pin

capacitance = val;
// soilmoisturepercent = map(soilMoistureValue, airValue, waterValue, 0, 100);
int valueMinDiff = abs(val - airValue);
int maxMinDiff = abs(airValue - waterValue);
Expand Down Expand Up @@ -98,8 +99,8 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
struct_message payload = struct_message();
memcpy(&payload, incomingData, sizeof(payload));
Serial.print("Bytes received: ");
Serial.printf("%d, moisture: %d from %s, %s, %d, %d, %d, %s\n", len, payload.moisture, payload.name, payload.hostAddress, payload.task, payload.type, payload.from, payload.msg);
Serial.printf("Bytes received at %s: ------\n", DEVICE_NAME);
Serial.printf("%d, moisture: %s, %d from %s, %d, %d, %d, %s\n", len, payload.moisture, payload.capacitance, payload.name, payload.task, payload.type, payload.from, payload.msg);
Serial.printf("=> msgId: %d\n", payload.msgId);
Serial.println("------\n");
String response = "";
Expand Down Expand Up @@ -168,7 +169,7 @@ void calibrate() {
sendData(response);
} else {
int task = Server.arg(0) == "air_value" ? CALIBRATE_AIR : CALIBRATE_WATER;
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, senderMac, receiverMac, task, BROADCAST, "", espInterval, from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, senderMac, receiverMac, task, BROADCAST, "", espInterval, from, capacitance);
payload.msgId = generateMessageHash(payload);
esp_now_send(broadcastAddress, (uint8_t *) &payload, sizeof(payload));
esp_now_send(leaderMacAddress, (uint8_t *) &payload, sizeof(payload));
Expand Down Expand Up @@ -196,7 +197,7 @@ void getMoisture() {
sendData(response);
} else {
Serial.printf("from: %d\n", from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", GET_MOISTURE, BROADCAST, "", espInterval, from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", GET_MOISTURE, BROADCAST, "", espInterval, from, capacitance);
payload.msgId = generateMessageHash(payload);
Serial.printf("why why why, %d, %d, %d, %d\n", payload.from, payload.task, payload.type, payload.msgId);
esp_now_send(broadcastAddress, (uint8_t *) &payload, sizeof(payload));
Expand All @@ -223,7 +224,7 @@ void queryESP() {
sendData(response);
} else {
Serial.printf("from: %d\n", from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", QUERY, BROADCAST, "", espInterval, from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", QUERY, BROADCAST, "", espInterval, from, capacitance);
payload.msgId = generateMessageHash(payload);
Serial.printf("why why why, %d, %d, %d, %d\n", payload.from, payload.task, payload.type, payload.msgId);
esp_now_send(broadcastAddress, (uint8_t *) &payload, sizeof(payload));
Expand All @@ -245,11 +246,11 @@ void pingESP() {
}
sprintf(payload.msg, "%d,%d,%d,%s,%s", airValue, waterValue, sensorPin, senderMac.c_str(), receiverMac.c_str());
String response = "{\"mac\": \"" + hostMac + "\", \"id\": " + String(DEVICE_ID) + fromStr + ", \"name\": \"" + DEVICE_NAME + "\", \"msg\": \"" + payload.msg + "\", \"task\": " + String(PING_BACK) + "}";
setPayload(payload, DEVICE_ID, DEVICE_NAME, "", hostMac, "", PING_BACK, BROADCAST, DEVICE_NAME, espInterval, WEB_REQUEST_RESULT);
setPayload(payload, DEVICE_ID, DEVICE_NAME, "", hostMac, "", PING_BACK, BROADCAST, DEVICE_NAME, espInterval, WEB_REQUEST_RESULT, capacitance);
sendData(response);
} else {
Serial.printf("from: %d\n", from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", PING, BROADCAST, DEVICE_NAME, espInterval, from);
setPayload(payload, DEVICE_ID, DEVICE_NAME, targetHostAddr, hostMac, "", PING, BROADCAST, DEVICE_NAME, espInterval, from, capacitance);
payload.msgId = generateMessageHash(payload);
Serial.printf("%d, %s, %s, %s, %d, %s\n", payload.id,payload.name,payload.hostAddress,payload.senderAddress,payload.task,payload.msg);
esp_now_send(broadcastAddress, (uint8_t *) &payload, sizeof(payload));
Expand Down Expand Up @@ -304,6 +305,13 @@ void updateESP32() {
} else if(task == "device_id") {
payload.task = UPDATE_DEVICE_ID;
payload.id = atoi(taskValue.c_str());
} else if(task == "enable_bluetooth") {
payload.task = ENABLE_BLUETOOTH;
} else if(task == "disable_bluetooth") {
payload.task = DISABLE_BLUETOOTH;
} else if(task == "update_pin") {
payload.task = UPDATE_PIN;
payload.espInterval = atoi(taskValue.c_str());
}
payload.msgId = generateMessageHash(payload);
Serial.printf("Broacast to: %s, %u\n", payload.hostAddress, gatewayReceiverAddress);
Expand All @@ -318,6 +326,10 @@ void updateESP32() {
}
}

void updatePin() {

}

String onHome(AutoConnectAux& aux, PageArgument& args) {
calculate();
Serial.println(moistureLevel);
Expand Down
1 change: 1 addition & 0 deletions esp-now/esp-now-mesh/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Serial.printf("%d, %d, %d, %d, %s, %d, %d, %s, %s\n", airValue,waterValue,sensor
} else {
Serial.printf("Adding peer: %u\n", peerInfo.peer_addr);
}

}

void loop() {
Expand Down
5 changes: 5 additions & 0 deletions esp-now/esp-now-plantmate-gateway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions esp-now/esp-now-plantmate-gateway/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
15 changes: 15 additions & 0 deletions esp-now/esp-now-plantmate-gateway/data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"uuid": {
"SERVICE_UUID": "4fafc201-1fb5-459e-8fcc-c5c9c331914b",
"CHARACTERISTIC_UUID": "beb5483e-36e1-4688-b7f5-ea07361b26a8"
},
"airValue": 3440,
"waterValue": 1803,
"sensorPin": 36,
"wsserver": "192.168.86.24",
"wsport": 3000,
"espInterval": 80000,
"wifiChannel": 0,
"receiverAddress": "",
"senderAddress": ""
}
Binary file not shown.
126 changes: 126 additions & 0 deletions esp-now/esp-now-plantmate-gateway/data/page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
[
{
"title": "Config",
"uri": "/update_config",
"menu": true,
"element": [
{
"name": "header",
"type": "ACText"
},
{
"name": "caption1",
"type": "ACText",
"value": "Air value"
},
{
"name": "airValue",
"type": "ACInput"
},
{
"name": "caption2",
"type": "ACText",
"value": "Water value"
},
{
"name": "waterValue",
"type": "ACInput"
},
{
"name": "caption3",
"type": "ACText",
"value": "Pin"
},
{
"name": "sensorPin",
"type": "ACInput"
},
{
"name": "caption4",
"type": "ACText",
"value": "WebSocket Server"
},
{
"name": "wsserver",
"type": "ACInput"
},
{
"name": "caption5",
"type": "ACText",
"value": "WebSocket Port"
},
{
"name": "wsport",
"type": "ACInput"
},
{
"name": "caption6",
"type": "ACText",
"value": "Receiver Mac Address"
},
{
"name": "receiverMac",
"type": "ACInput"
},
{
"name": "caption7",
"type": "ACText",
"value": "Sender Mac Address"
},
{
"name": "senderMac",
"type": "ACInput"
},
{
"name": "caption8",
"type": "ACText",
"value": "Interval"
},
{
"name": "espInterval",
"type": "ACInput"
},
{
"name": "save",
"type": "ACSubmit",
"value": "SAVE",
"uri": "/save_config"
}
]
},
{
"uri": "/save_config",
"title": "Save configuration",
"menu": false,
"element": [
{
"name": "results",
"type": "ACText",
"value": ""
}
]
},
{
"uri": "/",
"title": "Moisture reading",
"menu": false,
"element": [
{
"name": "moisture",
"type": "ACText",
"value": "Moisture: "
},
{
"name": "results",
"type": "ACText",
"value": "..."
},
{
"name": "save",
"type": "ACSubmit",
"value": "Read again...",
"uri": "/"
}
]
}
]
39 changes: 39 additions & 0 deletions esp-now/esp-now-plantmate-gateway/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions esp-now/esp-now-plantmate-gateway/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
28 changes: 28 additions & 0 deletions esp-now/esp-now-plantmate-gateway/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = esp-now-plantmate-gateway
description =

[env:esp-now-plantmate-gateway]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
upload_port = /dev/cu.usbserial-0001
upload_speed = 115200
monitor_speed = 115200
board_build.partitions = min_spiffs.csv
debug_build_flags = -Os
lib_deps =
hieromon/AutoConnect@^1.2.2
links2004/WebSockets@^2.3.7
build_flags =
-I../include
Loading