Commit b9e8c088 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Prj sender added

parent c65028ac
......@@ -26,10 +26,16 @@
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
#define RELE_1 0
#define RELE_2 22 //2
#define RELE_1 16
#define RELE_2 17 //2
int counter = 0;
void setup() {
pinMode(25,OUTPUT);
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.begin(115200);
while (!Serial);
......@@ -69,16 +75,31 @@ void onReceive(int packetSize)
str += p;
}
if(str == "hello 1")
if(str == "hello 0")
{
digitalWrite(RELE_1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(RELE_2, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
//delay(2000);
//digitalWrite(RELE_1, LOW); // turn the LED on (HIGH is the voltage level)
//digitalWrite(RELE_2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
// LoRa.beginPacket();
// LoRa.print("hello ");
// LoRa.print(counter%=2);
// LoRa.endPacket();
counter++;
} else if(str == "hello 1") {
digitalWrite(RELE_1, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(RELE_2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW
}
// print RSSI of packet
......
/*
ESP32 mDNS responder sample
This is an example of an HTTP server that is accessible
via http://esp32.local URL thanks to mDNS responder.
Instructions:
- Update WiFi SSID and password as necessary.
- Flash the sketch to the ESP32 board
- Install host software:
- For Linux, install Avahi (http://avahi.org/).
- For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
- For Mac OSX and iOS support is built in through Bonjour already.
- Point your browser to http://esp32.local, you should see a response.
*/
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiClient.h>
#include <SPI.h>
#include <LoRa.h>
const char* ssid = "Thomas";
const char* password = "viapiccardi47!!thomas";
// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);
// Pin definetion of WIFI LoRa 32
// HelTec AutoMation 2017 support@heltec.cn
#define SCK 5 // GPIO5 -- SX127x's SCK
#define MISO 19 // GPIO19 -- SX127x's MISO
#define MOSI 27 // GPIO27 -- SX127x's MOSI
#define SS 18 // GPIO18 -- SX127x's CS
#define RST 14 // GPIO14 -- SX127x's RESET
#define DI0 26 // GPIO26 -- SX127x's IRQ(Interrupt Request)
#define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
#define PABOOST true
int counter = 0;
void setup(void)
{
pinMode(25,OUTPUT);
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND,PABOOST)) {
Serial.println("Starting LoRa failed!");
while (1);
}
// register the receive callback
LoRa.onReceive(onReceive);
// Connect to WiFi network
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Set up mDNS responder:
// - first argument is the domain name, in this example
// the fully-qualified domain name is "esp8266.local"
// - second argument is the IP address to advertise
// we send our IP address on the WiFi network
if (!MDNS.begin("esp32")) {
Serial.println("Error setting up MDNS responder!");
while(1) {
delay(1000);
}
}
Serial.println("mDNS responder started");
// Start TCP (HTTP) server
server.begin();
Serial.println("TCP server started");
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
}
void loop(void)
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("");
Serial.println("New client");
// Wait for data from client to become available
while(client.connected() && !client.available()){
delay(1);
}
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
Serial.print("Invalid request: ");
Serial.println(req);
return;
}
req = req.substring(addr_start + 1, addr_end);
Serial.print("Request: ");
Serial.println(req);
client.flush();
String s;
if (req == "/")
{
IPAddress ip = WiFi.localIP();
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at ";
s += ipStr;
s += "</html>\r\n\r\n";
Serial.println("Sending 200");
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter%=2);
LoRa.endPacket();
// put the radio into receive mode
//LoRa.receive();
counter++;
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
else
{
s = "HTTP/1.1 404 Not Found\r\n\r\n";
Serial.println("Sending 404");
}
client.print(s);
Serial.println("Done with client");
}
void onReceive(int packetSize)
{
// received a packet
Serial.print("Received packet '");
// read packet
String str;
for (int i = 0; i < packetSize; i++)
{
char p = (char)LoRa.read();
Serial.print(p);
str += p;
}
if(str == "hello 0")
{
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level)
} else if(str == "hello 1") {
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.print(str);
Serial.print(" ");
Serial.println(LoRa.packetRssi());
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment