element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Projects
  • Products
  • Arduino
  • Arduino Projects
  • More
  • Cancel
Arduino Projects
Blog Arduino UNO R4 WIFI - Remote Weather Station Demo
  • Blog
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: javagoza
  • Date Created: 3 Jul 2023 4:36 PM Date Created
  • Views 9838 views
  • Likes 15 likes
  • Comments 9 comments
  • wifi
  • r4
  • weather station
  • arduino
  • remote
Related
Recommended

Arduino UNO R4 WIFI - Remote Weather Station Demo

javagoza
javagoza
3 Jul 2023
Arduino UNO R4 WIFI - Remote Weather Station Demo

Arduino UNO R4 Wifi 

Just received an Arduino UNO R4 Wifi board and an R4 Minima board.

I wanted to test the new display and the Wi-Fi connection by making a small demo that connects to an online weather service and shows the recovered temperature.
In the demo I had provided an animation while connecting to the server but it is very unstable and occasionally crashes so I have removed the animations.

The service calls this open API

https://open-meteo.com/en/docs#latitude=41.6561&longitude=-0.8773&hourly=&daily=&current_weather=true&timezone=Europe%2FBerlin&forecast_days=1

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Displaying custom numbers. Here the online received temperature showing 33 C

image

Waiting icon when connecting with online service

image

Console output


Starting connection to server...
connected to server
{"latitude":41.66,"longitude":-0.8800001,"generationtime_ms":0.5170106887817383,"utc_offset_seconds":7200,"timezone":"Europe/Berlin","timezone_abbreviation":"CEST","elevation":208.0,"current_weather":{"temperature":33.0,"windspeed":9.8,"winddirection":276.0,"weathercode":3,"is_day":1,"time":"2023-07-03T17:00"}}

Temperature C: 33

Source code

You will have to add the arduino JSON libraries and WIFIS3

WiFiWeatherStation.ino main sketch

// WiFiWeatherStation.ino
#include "Arduino_LED_Matrix.h"
#include "numbers.h"

ArduinoLEDMatrix matrix;


#include "WiFiS3.h"
#include <Arduino_JSON.h>
#include <assert.h>

#include "arduino_secrets.h"

unsigned long lastConnectionTime = 0;               // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L;  // delay between updates, in milliseconds
JSONVar myObject;
unsigned char frame[8][12];
int temperature = 0;
///////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;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(202,61,229,161);  // numeric IP for api.open-meteo.com (no DNS)
char server[] = "api.open-meteo.com";  // name address for api.open-meteo.com (using DNS)
// https://api.open-meteo.com/v1/forecast?latitude=41.6561&longitude=-0.8773&current_weather=true&timezone=Europe%2FBerlin

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void displayDec(int number) {
  int decs = (number / 10) % 10;
  int units = number % 10;  //
  for (int i = 0; i < 8; ++i) {
    for (int j = 0; j<6 > 0; ++j) {
      frame[i][j] = numbers[decs][i][j];
    }
    for (int j = 0; j<6 > 0; ++j) {
      frame[i][j + 6] = numbers[units][i][j];
    }
  }

  matrix.renderBitmap(frame, 8, 12);
}

/* -------------------------------------------------------------------------- */
void setup() {


  /* -------------------------------------------------------------------------- */
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ;  // wait for serial port to connect. Needed for native USB port only
  }


  matrix.begin();

  matrix.loadFrame(clock_animation[0]);
  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true)
      ;
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // 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);
  }
  // you're connected now, so print out the status:
  printWifiStatus();
}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_response() {
  /* -------------------------------------------------------------------------- */
  uint32_t received_data_num = 0;
  uint32_t data_num = 0;
  bool jsonDetected = false;
  char data[500];
  while (client.available() && data_num < 500) {
    /* actual data reception */
    char c = client.read();
    // json start detected
    if ('{' == c) {
      jsonDetected = true;
    }
    if (jsonDetected) {
      data[data_num++] = c;
    }
  }
  //data[received_data_num] = 0;
  if (jsonDetected) {
    Serial.println(data);
    myObject = JSON.parse(data);
    Serial.print("Temperature C: ");
    if (myObject.hasOwnProperty("current_weather")) {

      temperature = (double)myObject["current_weather"]["temperature"];
      Serial.println(temperature);
      displayDec(temperature);
    }
  }
}

/* -------------------------------------------------------------------------- */
void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  read_response();
  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    http_request();
  }
}

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
  /* -------------------------------------------------------------------------- */
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board'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 http_request() {

  matrix.loadFrame(clock_animation[0]);

  client.stop();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /v1/forecast?latitude=41.6561&longitude=-0.8773&current_weather=true&timezone=Europe%2FBerlin HTTP/1.1");
    client.println("Host: api.open-meteo.com");
    client.println("Connection: close");
    client.println();
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

Bitmap representation of decimal digits 0 to 9, and the hourglass icon

// numbers.h

uint8_t numbers[10][8][8] = {
    {
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 } },
  {
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 0 },
  { 1, 0, 0, 0, 0 },
  { 1, 1, 1, 1, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 } },
  {
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 0 },
  { 1, 0, 0, 0, 0 },
  { 1, 0, 0, 0, 0 },
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 0 },
  { 1, 0, 0, 0, 0 },
  { 1, 0, 0, 0, 0 },
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 } },
{
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 } },
  {
  { 1, 1, 1, 1, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 0, 0, 0, 1 },
  { 1, 1, 1, 1, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 },
  { 0, 0, 0, 0, 1 } }


};
const uint32_t clock_animation[][4] = {
	{
		0x1f01f00e,
		0x400400,
		0xa01101f0,
		66
	},
	{
		0x1f01700e,
		0x400400,
		0xe01101f0,
		66
	},
	{
		0x1f01300e,
		0x400400,
		0xe01901f0,
		66
	},
	{
		0x1f01100e,
		0x400400,
		0xa01f01f0,
		66
	},
	{
		0x1f01100a,
		0x400400,
		0xe01f01f0,
		66
	}
  // ,
	// {
	// 	0x30c29,
	// 	0x43f439c3,
	// 	0xc000000,
	// 	66
	// },
	// {
	// 	0x30c29,
	// 	0x42f439c3,
	// 	0xc000000,
	// 	66
	// }
};

Here your wifi credentials

// arduino_secrets.h
#define SECRET_SSID ""
#define SECRET_PASS ""

image

image

Enjoy it!

Elevate your DIY projects with genuine arduino products! Check out the complete collection at any of our online stores.

  • Sign in to reply
  • papavask
    papavask 10 months ago

    Great demo !!!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • k119
    k119 over 1 year ago in reply to javagoza

    Thanks that worked.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 1 year ago in reply to k119

    Yes, you can connect to a local webserver, you can use the IP instead of the name of the server.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • k119
    k119 over 1 year ago

    Nice demo. I have a question, could the char server[] = "api.open-meteo.com" be changed to connect to a local web server running on another Arduino?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 2 years ago in reply to Jan Cumps

    Nice demo Jan.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube