1. Alessio Caiazza
  2. hotspot

Commits

Alessio Caiazza  committed e0ea934

SoftSerial working POC

  • Participants
  • Parent commits 9597e91
  • Branches default

Comments (0)

Files changed (2)

File termostato_rx/termostato_rx.ino

View file
-#include <VirtualWire.h>
-#include <EasyTransferVirtualWire.h>
+#include <SoftEasyTransfer.h>
+#include <SoftwareSerial.h>
 #include "../termostato/protocol.h"
 
 
 #define LOST_SIGNAL_TRASHOLD 30 * 1000
 #define LOOP_DELAY 250
 
-EasyTransferVirtualWire ET; 
+SoftwareSerial mySerial(RADIO_IN, 3);
+
+
+//create object
+SoftEasyTransfer ET; 
+
 
 //give a name to the group of data
 HOTSPOT_MSG mydata;
 bool status;
 
 void setup(){
-  ET.begin(details(mydata));
-
-  // Initialise the IO and ISR
-  //vw_set_ptt_inverted(true); // Required for DR3100
-  vw_setup(2000);  // Bits per sec
-
-  vw_rx_start();       // Start the receiver PLL running
+  mySerial.begin(9600);
+  ET.begin(details(mydata), &mySerial);
   
   pinMode(STATUS_LED, OUTPUT);
   pinMode(RELE, OUTPUT);
   time = millis();
   connectionLost = true;
   status = false;
+  Serial.begin(9600);
 }
 
 void loop(){
   if(ET.receiveData()){
     connectionLost = false;
     time = millis();
-    bool outChanged = false;
     switch(mydata.cmd) {
       case PING:
-        outChanged = status != mydata.args;
         status = mydata.args;
+        Serial.print("PING: status "); Serial.println(status);
         break;
-      default:
-        status = mydata.cmd == SWITCH_ON;
-        outChanged = true;
+      case SWITCH_ON:
+        status = true;
+        Serial.println("SWITCH_ON");
+        break;
+      case SWITCH_OFF:
+        status = false;
+        Serial.println("SWITCH_OFF");
+        break;
     } 
-    if(outChanged) {
-      digitalWrite(RELE, status);
-      digitalWrite(STATUS_LED, status);
-    }
+    digitalWrite(RELE, status);
+    digitalWrite(STATUS_LED, status);
   } else {
     unsigned long now = millis();
-    if(time - now > LOST_SIGNAL_TRASHOLD)
+    if(now - time > LOST_SIGNAL_TRASHOLD)
       connectionLost = true;
 
     if(connectionLost) {

File termostato_tx/termostato_tx.ino

View file
-#include <VirtualWire.h>
-#include <EasyTransferVirtualWire.h>
+#include <SoftEasyTransfer.h>
+#include <SoftwareSerial.h>
 #include "../termostato/protocol.h"
 
 #define GENERAl_SWITCH 7
 #define PING_FREQ 15000
 #define NUMSAMPLES 5
 
-
-
-EasyTransferVirtualWire ET; 
+SoftEasyTransfer ET; 
+SoftwareSerial mySerial(3, RADIO_OUT);
 
 
 
 bool status;
 
 void setup(){  
-  ET.begin(details(mydata));
+  mySerial.begin(9600);
+  ET.begin(details(mydata), &mySerial);
 
-  // Initialise the IO and ISR
-  //vw_set_ptt_inverted(true); // Required for DR3100
-  vw_setup(2000);  // Bits per sec
   
   pinMode(STATUS_LED, OUTPUT);
   pinMode(GENERAl_SWITCH, INPUT);
   pinMode(TEMP, INPUT);
    
   Serial.begin(9600);
-  //analogReference(EXTERNAL);
   lastPing = 0;
   status = false;
   digitalWrite(STATUS_LED, status);
     lastPing = now;
 		mydata.cmd = PING;
 		mydata.args = (int)status;
+    Serial.println("PING");
 		ET.sendData();
 	}
 
 		mydata.args = 0;
     status = false;
 		mustSend = true;
+    Serial.println("SWITCH_OFF");
 	} else if (!status && temp < trashold) {
 		mydata.cmd = SWITCH_ON;
 		mydata.args = 0;
     status = true;
 		mustSend = true;
+    Serial.println("SWITCH_ON");
 	}
 
 	if(mustSend)