Sketch Monitoraggio fiume: lato Server
/* Aspetta l'inserimento del carattere a per accendere sul lato Client il Led
s per spegnerlo
p per aumentare la potenza di trasmissione a 100 mW (potenza soggetta a normative)
*/
#include "LoraNode.h" //Include library
LoraNode Node(1); //Instance node 1 (server)
bool SHIELD=true; //Flag to verify correct link with radio module
bool ack=false;
int maxdevice=15;
char Comando; // Riceve il codice ASCII del numero
int timing=10000; //server scans all devices every 10 seconds
int PWR=5; //transmit power. 4 = 50 mW; 5 = 100 mW
void setup ()
{
 Serial.begin(9600);
 if (!Node.begin()) {Serial.println("No LoRa module!");SHIELD=false;return;}
 SX.setPower(PWR); // Setta alla potenza indicata
 Node.printConfig(); //Print radio config (for information)
 Node.printAddresses(); //Print network data (for information)
}
void loop ()
{
 Serial.println("Attendo comando da tastiera");

 //------------------------------------------------------
 while (Serial.available()==0)//Attende carattere da tastiera
 {
 delay (10);
 }
 Comando= Serial.read();
 //----------------------------------------------------
 Serial.println(Comando);
if (!SHIELD) return;
 bool ack=false;
  switch (Comando)
 {
 case 97: // Carattere a del comando AVVIA
 Node.writeMessage(2,"a",100); //Send interrogation
 ack=Node.newMessAvailable(2,3000); //wait message from dev 2 for 3 sec
 if (!ack) norep(2); //if no reply (timeout)
 else getVal(2); //if replay manage it
 delay(timing);
 break;
 case 115: // Carattere s del comando STOP
 Node.writeMessage(2,"s",100); //Send interrogation
 ack=Node.newMessAvailable(2,3000); //wait message from dev 2 for 3 sec
 if (!ack) norep(2); //if no reply (timeout)
 else getVal(2); //if replay manage it
 delay(timing);
 break;
 case 112: // Carattere p del comando POTENZA
 Node.writeMessage(2,"p",100); //Send interrogation
 ack=Node.newMessAvailable(2,3000); //wait message from dev 2 for 3 sec
 if (!ack) norep(2); //if no reply (timeout)
 else getVal(2); //if replay manage it
 delay(timing);
 break;
 }
}
void getVal(int dev)
{
 char* mess=Node.getMessage();
 int val=atoi(mess);
 manageMess(dev,val);
}
void manageMess(int dev,int val)
{
 Serial.print("Device: ");Serial.print(dev);Serial.print(" value: ");Serial.println(val);
 //or change with your code for devices replay
}
void norep(int dev)
{
 Serial.print("Device ");Serial.print(dev);Serial.println(" no responding!");
}

 