Sending data using Arduino MKR Wifi 1010

Hi,
I am attempting to send data wirelessly to my laptop using Arduino MKR WiFi 1010. My Arduino is getting connected to the network but how do I send the temperature readings to the serial monitor wirelessly? Everytime I disconnect the USB, the connection to the serial monitor dies (it makes sense). I want to save the data as an excel file - any suggestions on how to do that? Below is my code. Would appreciate the help greatly!

/*

  MKR1000 - MKR WiFi 1010 - MKR VIDOR 4000 WiFi RTC

  This sketch asks NTP for the Linux epoch and sets the internal Arduino MKR1000's RTC accordingly.

  created 08 Jan 2016

  by Arturo Guadalupi <a.guadalupi@arduino.cc>

  modified 26 Sept 2018

  http://arduino.cchttps://www.arduino.cc/en/Tutorial/WiFiRTC

  This code is in the public domain.

*/

#include <SPI.h>
#include <WiFiNINA.h> //Include this instead of WiFi101.h as needed
#include <WiFiUdp.h>
#include <RTCZero.h>
float temperature = 0;
int tempPin = 0;
RTCZero rtc;

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
//int keyIndex = 0;                           // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

const int GMT = 8; //change this to adapt it to your time zone

void setup() {

  Serial.begin(115200);

  // check if the WiFi module works

  if (WiFi.status() == WL_NO_SHIELD) {

    Serial.println("WiFi shield not present");

    // don't continue:

    while (true);

  }

  // attempt to connect to WiFi network:

  while ( status != WL_CONNECTED) {

    Serial.print("Attempting to connect to SSID: ");

    Serial.println(ssid);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:

    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:

    delay(10000);

   // init the CSV file with headers
   Serial.println("temperature");     

  }

  // you're connected now, so print out the status:

  printWiFiStatus();

  rtc.begin();

  unsigned long epoch;

  int numberOfTries = 0, maxTries = 6;

  do {

    epoch = WiFi.getTime();

    numberOfTries++;

  }

  while ((epoch == 0) && (numberOfTries < maxTries));

  if (numberOfTries == maxTries) {

    Serial.print("NTP unreachable!!");

    while (1);

  }

  else {

    Serial.print("Epoch received: ");

    Serial.println(epoch);

    rtc.setEpoch(epoch);

    Serial.println();

  }
}

void loop() {
  temperature = analogRead(tempPin);
  Serial.print(temperature);
  Serial.println();
  printDate();
  printTime();
  Serial.println();
  delay(1000);
}

void printTime()
{

  print2digits(rtc.getHours() + GMT);

  Serial.print(":");

  print2digits(rtc.getMinutes());

  Serial.print(":");

  print2digits(rtc.getSeconds());

  Serial.println();
}

void printDate()
{

  Serial.print(rtc.getDay());

  Serial.print("/");

  Serial.print(rtc.getMonth());

  Serial.print("/");

  Serial.print(rtc.getYear());

  Serial.print(" ");
}

void printWiFiStatus() {

  // print the SSID of the network you're attached to:

  Serial.print("SSID: ");

  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:

  IPAddress ip = WiFi.localIP();

  Serial.print("IP Address: ");

  Serial.println(ip);

  // print the received signal strength:

  long rssi = WiFi.RSSI();

  Serial.print("signal strength (RSSI):");

  Serial.print(rssi);

  Serial.println(" dBm");
}

void print2digits(int number) {

  if (number < 10) {

    Serial.print("0");

  }

  Serial.print(number);
}

You might find this useful: Link to a very basic tutorial about TCP (evolved to: TCP-socket democode to send / receive data / characters similar to serial
Create a server with the example code then connect to it using PuTTY or similar. PuTTY allows you to save the data to a text file, do that then open it with Excel.

Yes this helped! Thank you:)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.