├── .gitattributes ├── SAMPLE_RECEIVER └── SAMPLE_RECEIVER.ino ├── SAMPLE_SENDER └── SAMPLE_SENDER.ino ├── dht11_SENDER └── dht11_SENDER.ino └── oled_RECEIVER └── oled_RECEIVER.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /SAMPLE_RECEIVER/SAMPLE_RECEIVER.ino: -------------------------------------------------------------------------------- 1 | /* Codes that Receives JSON data using ESPNOW Protocol 2 | 3 | * Developed by Jay Joshi 4 | * github.com/JayJoshi16 5 | * . 6 | * 7 | * Modified by Sachin Soni 8 | * 9 | * Developed for techiesms 10 | * https://www.youtube.com/techiesms 11 | */ 12 | 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | String jsondata; 19 | StaticJsonDocument<200> doc; 20 | 21 | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { 22 | 23 | char* buff = (char*) incomingData; //char buffer 24 | jsondata = String(buff); //converting into STRING 25 | Serial.print("Recieved "); 26 | Serial.println(jsondata); //Complete JSON data will be printed here 27 | DeserializationError error = deserializeJson(doc, jsondata); 28 | 29 | if (!error) { 30 | int a = doc["a"]; 31 | const char* b = doc["b"]; 32 | Serial.println(a); //values of a 33 | Serial.println(b); //values of b 34 | } 35 | 36 | else { 37 | Serial.print(F("deserializeJson() failed: ")); //Just in case of an ERROR of ArduinoJSon 38 | Serial.println(error.f_str()); 39 | return; 40 | } 41 | } 42 | 43 | void setup() { 44 | 45 | Serial.begin(115200); 46 | WiFi.mode(WIFI_STA); 47 | 48 | if (esp_now_init() != ESP_OK) { //Init ESPNOW 49 | Serial.println("Error initializing ESP-NOW"); 50 | return; 51 | } 52 | 53 | esp_now_register_recv_cb(OnDataRecv); //Reciever CallBack function 54 | 55 | 56 | } 57 | 58 | void loop() { 59 | 60 | } 61 | -------------------------------------------------------------------------------- /SAMPLE_SENDER/SAMPLE_SENDER.ino: -------------------------------------------------------------------------------- 1 | /* Codes that Sends JSON data using ESPNOW Protocol 2 | 3 | * Developed by Jay Joshi 4 | * github.com/JayJoshi16 5 | * 6 | * Modified by Sachin Soni 7 | * 8 | * Developed for techiesms 9 | * https://www.youtube.com/techiesms 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | uint8_t broadcastAddress[] = {0xC8, 0xC9, 0xA3, 0xF9, 0xE9, 0x68}; //Destination ESP32's MAC Address 16 | 17 | #include 18 | String jsondata; 19 | StaticJsonDocument<200> doc; 20 | 21 | 22 | //function for Sending data 23 | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { 24 | Serial.print("\r\nLast Packet Send Status:\t"); 25 | Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); 26 | } 27 | 28 | void setup() { 29 | 30 | Serial.begin(115200); 31 | WiFi.mode(WIFI_STA); 32 | 33 | // Init ESP-NOW 34 | if (esp_now_init() != ESP_OK) { 35 | Serial.println("Error initializing ESP-NOW"); 36 | return; 37 | } 38 | 39 | // Register peer 40 | esp_now_peer_info_t peerInfo; 41 | memset(&peerInfo, 0, sizeof(peerInfo)); 42 | for (int ii = 0; ii < 6; ++ii ) 43 | { 44 | peerInfo.peer_addr[ii] = (uint8_t) broadcastAddress[ii]; 45 | } 46 | peerInfo.channel = 0; 47 | peerInfo.encrypt = false; 48 | 49 | // Add peer 50 | if (esp_now_add_peer(&peerInfo) != ESP_OK) { 51 | Serial.println("Failed to add peer"); 52 | return; 53 | } 54 | 55 | 56 | esp_now_register_send_cb(OnDataSent); 57 | 58 | } 59 | 60 | void loop() 61 | { 62 | jsondata = ""; //clearing String after data is being sent 63 | 64 | doc["a"] = 1; 65 | doc["b"] = "ON"; 66 | serializeJson(doc, jsondata); //Serilizing JSON 67 | /* 68 | * { 69 | * "a" : 1, 70 | * "b" : "ON" 71 | * 72 | * } 73 | * 74 | * 75 | */ 76 | esp_now_send(broadcastAddress, (uint8_t *) jsondata.c_str(), sizeof(jsondata) + 2); //Sending "jsondata" 77 | Serial.println(jsondata); 78 | delay(1000); 79 | 80 | 81 | 82 | jsondata = ""; //clearing String after data is being sent 83 | 84 | doc["a"] = 0; 85 | doc["b"] = "OFF"; 86 | serializeJson(doc, jsondata); 87 | esp_now_send(broadcastAddress, (uint8_t *) jsondata.c_str(), sizeof(jsondata) + 2); 88 | Serial.println(jsondata); 89 | delay(1000); 90 | } 91 | -------------------------------------------------------------------------------- /dht11_SENDER/dht11_SENDER.ino: -------------------------------------------------------------------------------- 1 | /* Codes that Sends JSON data using ESPNOW Protocol 2 | 3 | * Developed by Jay Joshi 4 | * github.com/JayJoshi16 5 | * 6 | * Modified by Sachin Soni 7 | * 8 | * Developed for techiesms 9 | * https://www.youtube.com/techiesms 10 | */ 11 | 12 | #include 13 | #include 14 | #include "DHT.h" 15 | 16 | #define DHTPIN 15 17 | 18 | uint8_t broadcastAddress[] = {0xC8, 0xC9, 0xA3, 0xF9, 0xE9, 0x68}; //Destination ESP32's MAC Address 19 | 20 | #include 21 | String jsondata; 22 | StaticJsonDocument<200> doc; 23 | 24 | #define DHTTYPE DHT11 25 | 26 | DHT dht(DHTPIN, DHTTYPE); 27 | 28 | //function for Sending data 29 | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { 30 | Serial.print("\r\nLast Packet Send Status:\t"); 31 | Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); 32 | } 33 | 34 | void setup() { 35 | 36 | Serial.begin(115200); 37 | WiFi.mode(WIFI_STA); 38 | dht.begin(); 39 | // Init ESP-NOW 40 | if (esp_now_init() != ESP_OK) { 41 | Serial.println("Error initializing ESP-NOW"); 42 | return; 43 | } 44 | 45 | // Register peer 46 | esp_now_peer_info_t peerInfo; 47 | memset(&peerInfo, 0, sizeof(peerInfo)); 48 | for (int ii = 0; ii < 6; ++ii ) 49 | { 50 | peerInfo.peer_addr[ii] = (uint8_t) broadcastAddress[ii]; 51 | } 52 | peerInfo.channel = 0; 53 | peerInfo.encrypt = false; 54 | 55 | // Add peer 56 | if (esp_now_add_peer(&peerInfo) != ESP_OK) { 57 | Serial.println("Failed to add peer"); 58 | return; 59 | } 60 | 61 | 62 | esp_now_register_send_cb(OnDataSent); 63 | 64 | } 65 | 66 | void loop() { 67 | 68 | float h = dht.readHumidity(); 69 | float t = dht.readTemperature(); 70 | 71 | jsondata = ""; //clearing String after data is being sent 72 | 73 | doc["temp"] = t; 74 | doc["hum"] = h; 75 | serializeJson(doc, jsondata); //Serilizing JSON 76 | esp_now_send(broadcastAddress, (uint8_t *) jsondata.c_str(), jsondata.length()); //Sending "jsondata" 77 | Serial.println(jsondata); 78 | Serial.println((jsondata.length())); 79 | delay(1000); 80 | } 81 | -------------------------------------------------------------------------------- /oled_RECEIVER/oled_RECEIVER.ino: -------------------------------------------------------------------------------- 1 | /* Codes that Receives JSON data using ESPNOW Protocol 2 | 3 | Developed by Jay Joshi 4 | github.com/JayJoshi16 5 | 6 | Modified by Sachin Soni 7 | 8 | Developed for techiesms 9 | https://www.youtube.com/techiesms 10 | */ 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | #define SCREEN_WIDTH 128 // OLED display width, in pixels 21 | #define SCREEN_HEIGHT 64 // OLED display height, in pixels 22 | 23 | #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) 24 | #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 25 | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); 26 | 27 | String jsondata; 28 | StaticJsonDocument<200> doc; 29 | 30 | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { 31 | 32 | char* buff = (char*) incomingData; //char buffer 33 | jsondata = String(buff); //converting into STRING 34 | Serial.print("Recieved "); 35 | Serial.println(jsondata); //Complete JSON data will be printed here 36 | DeserializationError error = deserializeJson(doc, jsondata); 37 | 38 | if (!error) { 39 | float temp = doc["temp"]; 40 | float hum = doc["hum"]; 41 | Serial.println(temp); //values of a 42 | Serial.println(hum); //values of b 43 | 44 | display.clearDisplay(); 45 | display.setTextSize(2); // Normal 1:1 pixel scale 46 | display.setTextColor(SSD1306_WHITE); // Draw white text 47 | display.setCursor(0, 0); // Start at top-left corner 48 | display.print("Temp:"); 49 | display.println(temp); 50 | display.print("Hum:");. 51 | display.println(hum); 52 | display.display(); 53 | } 54 | 55 | else { 56 | Serial.print(F("deserializeJson() failed: ")); //Just in case of an ERROR of ArduinoJSon 57 | Serial.println(error.f_str()); 58 | return; 59 | } 60 | } 61 | 62 | void setup() { 63 | 64 | Serial.begin(115200); 65 | WiFi.mode(WIFI_STA); 66 | 67 | if (esp_now_init() != ESP_OK) { //Init ESPNOW 68 | Serial.println("Error initializing ESP-NOW"); 69 | return; 70 | } 71 | 72 | esp_now_register_recv_cb(OnDataRecv); //Reciever CallBack function 73 | 74 | 75 | if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { // Address 0x3D for 128x64 76 | Serial.println(F("SSD1306 allocation failed")); 77 | for (;;); 78 | } 79 | 80 | } 81 | 82 | void loop() { 83 | 84 | } 85 | --------------------------------------------------------------------------------