Skip to content

[MKC-1070] Hannes7eicher/giga example fix #1406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tags:
- Audio Jack
author: 'Jacob Hylén'
hardware:
- hardware/08.mega/boards/giga-r1-wifi
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: Guide to GIGA R1 Advanced ADC/DAC and Audio Features
description: 'Learn how to use the ADC/DAC features, along with useful examples on how to generate waveforms and play audio from a file.'
author: José Bagur, Taddy Chung & Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
tags: [ADC, DAC, Audio, USB]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ title: GIGA R1 Camera Guide
description: Learn about the GIGA R1 WiFi's camera connector, and how to use existing examples.
tags: [ArduCAM, Camera, Processing]
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
---

The GIGA R1 has a dedicated camera connector that allows certain camera modules to mount directly on the board. This makes it possible to add machine vision to your GIGA R1 board without much effort at all.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: Guide to GIGA R1 Dual Cores
description: Learn how to access and control the M4 and M7 cores on the GIGA R1, and how to communicate between them using RPC.
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
tags: [Dual Core, M4, M7]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: Getting Started with GIGA R1 WiFi
description: A step-by-step guide to install the board package needed for the GIGA R1 WiFi board.
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
tags: [GIGA R1 WiFi, Installation, IDE]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: MicroPython on the GIGA R1
description: Get started with MicroPython on the GIGA R1.
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
tags: [MicroPython, dfu-util]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: Guide to Arduino GIGA USB Features
description: 'Learn how you can turn your USB device into a mouse or keyboard, how to read & write to a USB mass storage, and connecting a keyboard via the USB-A connector.'
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
tags: [USB, USB HID, USBHost, Mass Storage, Keyboard, Mouse]
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
title: GIGA R1 WiFi Network Examples
description: Discover examples compatible with the WiFi library included in the GIGA core.
author: Karl Söderby
hardware:
- hardware/10.mega/boards/giga-r1-wifi
software:
- ide-v1
- ide-v2
- web-editor
tags: [Wi-Fi, Web Server, AP Mode, SSL, UDP]
---

Expand Down Expand Up @@ -156,117 +162,187 @@ void printMacAddress(byte mac[]) {

```arduino
/*
This example connects to an unencrypted WiFi network.
Then it prints the MAC address of the WiFi module,
the IP address obtained, and other network details.
Udp NTP Client

Circuit:
* GIGA R1 WiFi
Get the time from a Network Time Protocol (NTP) time server
Demonstrates use of UDP sendPacket and ReceivePacket
For more on NTP time servers and the messages needed to communicate with them,
see http://en.wikipedia.org/wiki/Network_Time_Protocol

created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
created 4 Sep 2010
by Michael Margolis
modified 9 Apr 2012
by Tom Igoe
modified 22 March 2023
by Karl Söderby
*/
modified 28 Dec 2022
by Giampaolo Mancini

This code is in the public domain.
*/

#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <mbed_mktime.h>

#include "arduino_secrets.h"
int status = WL_IDLE_STATUS;
#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 status = WL_IDLE_STATUS; // the WiFi radio's status
char ssid[] = ""; // your network SSID (name)
char 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)

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
}
unsigned int localPort = 2390; // local port to listen for UDP packets

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
// IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
constexpr auto timeServer { "pool.ntp.org" };

// wait 10 seconds for connection:
delay(10000);
}
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message

// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets

}
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;

void loop() {
// check the network connection once every 10 seconds:
delay(10000);
printCurrentNet();
}
constexpr unsigned long printInterval { 1000 };
unsigned long printNow {};

void printWifiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}

void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// 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);

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// wait 10 seconds for connection:
delay(10000);
}

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
Serial.println("Connected to WiFi");
printWifiStatus();

setNtpTime();

// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption, HEX);
Serial.println();
}

void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
void loop()
{
if (millis() > printNow) {
Serial.print("System Clock: ");
Serial.println(getLocaltime());
printNow = millis() + printInterval;
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}

void setNtpTime()
{
Udp.begin(localPort);
sendNTPpacket(timeServer);
delay(1000);
parseNtpPacket();
}

// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(const char * address)
{
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;

Udp.beginPacket(address, 123); // NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}

unsigned long parseNtpPacket()
{
if (!Udp.parsePacket())
return 0;

Udp.read(packetBuffer, NTP_PACKET_SIZE);
const unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
const unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
const unsigned long secsSince1900 = highWord << 16 | lowWord;
constexpr unsigned long seventyYears = 2208988800UL;
const unsigned long epoch = secsSince1900 - seventyYears;
set_time(epoch);

#if defined(VERBOSE)
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// print Unix time:
Serial.println(epoch);

// print the hour, minute and second:
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(':');
if (((epoch % 3600) / 60) < 10) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}
}
Serial.println();
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(':');
if ((epoch % 60) < 10) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
Serial.println(epoch % 60); // print the second
#endif

return epoch;
}

String getLocaltime()
{
char buffer[32];
tm t;
_rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT);
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
return String(buffer);
}

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");
}
```

Expand Down