Use Terminal Widget as a remote serial monitor?

Hi Costas

Didn’t understand the timer part at first, but got it working. Here is the code… Thanks for the advise

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>

SoftwareSerial mySerial(3, 2); // RX, TX
WidgetTerminal terminal(V1);
WidgetLED LED1(V0);

char auth[] = "Your Token";

// Input og output from Alarm Arduino true state for alarm On Off (On = HIGH)
const int AlarmStatRead = 4;
const int Bly_AlarmOnOff = A0;

// Variabel
int AlarmLedOnOff = 0;
int Old_AlarmLedOnOff = 0;

// Setup network static IP  
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress server_ip (46, 101, 143, 225);
IPAddress arduino_ip ( 192, 168,   1, 160);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192, 168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

// the timer objects
SimpleTimer timer;

void setup() {
  // initialize pins as input and output
  pinMode(AlarmStatRead, INPUT);
  pinMode(Bly_AlarmOnOff, OUTPUT);
  digitalWrite(Bly_AlarmOnOff, HIGH); // pull up A0 - also alarm on when reboot
  Serial.begin(9600);
  
  // SoftwareSerial communication setup
  while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  
  timer.setInterval(1000, Alarm_On_Off);
  timer.setInterval(500, Sent_serial);
}

  // Subrutine ( Alarm_On_Off )
  void Alarm_On_Off() {
         // read the state of Alarm input to variables
         AlarmLedOnOff = digitalRead(AlarmStatRead);
         // Check if Alarm is On or Off - Only run the (if/else(function)) when input changed  
         if  (AlarmLedOnOff != Old_AlarmLedOnOff){ 
            if  (AlarmLedOnOff == HIGH){
                 LED1.on();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }else{   
                 LED1.off();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }
         }
  }
  
  // Subrutine ( Sent_serial ) data to blynk terminal widget
  void Sent_serial() {
         // Sent serial data to Blynk terminal - Unlimited string readed
         String content = "";  //null string constant ( an empty string )
         char character;
         while(mySerial.available()) {
              character = mySerial.read();
              content.concat(character);
              Serial.println();  
         }
         if (content != "") {
              Blynk.virtualWrite (V1, content);
         }  
  }

void loop() {
  Blynk.run();
  timer.run();
}
3 Likes