Skip to content

Commit e23f715

Browse files
committed
add m0 wifi support
1 parent fb6f739 commit e23f715

8 files changed

+129
-20
lines changed

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
## Building Project
44

55
1. Ensure you're on (at least) version 1.6.13 of the Arduino IDE
6-
1. Unzip libraries file and place the contents in your Arduino user libraries folder. (Usually `~/Documents/Arduino/libraries`)
6+
1. Place the contents of the libraries directory in your Arduino user libraries directory. (Usually `~/Documents/Arduino/libraries`)
77
1. Set up WICED Feather using [steps here](https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi/).
88
1. Set up M0 Feather using [steps here](https://learn.adafruit.com/adafruit-feather-m0-basic-proto/setup).
9+
1. Set up M0 WiFi Feather using [steps here](https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/using-the-wifi-module). Be sure to do the version check as described.
10+
1. In `user_config.h`, uncomment the appropriate line depending on which microprocessor board you are using. Only one board type line in this file should be uncommented.
911

1012
## Software
1113

@@ -35,11 +37,16 @@
3537
- 10K ohm resistor
3638
- Male/Female Headers (cut to size)
3739

38-
### WiFi
40+
### WICED WiFi
3941

4042
- All base parts
4143
- [WICED WiFi Feather](https://www.adafruit.com/product/3056)
4244

45+
### M0 WiFi
46+
47+
- All base parts
48+
- [M0 WiFi Feather](https://www.adafruit.com/product/3010)
49+
4350
### Cellular/GSM(2G)
4451

4552
- All base parts
@@ -48,6 +55,8 @@
4855
- [SIM800L GSM Breakout Module](http://www.ebay.com/itm/SIM800L-Quad-band-Network-Mini-GPRS-GSM-Breakout-Module-Ships-from-California-/172265821650?hash=item281bd7d5d2:g:97gAAOSwls5Y5qFG)
4956

5057

51-
### Headseek Featherwing Schematics
58+
### Headseek Featherwing Board
59+
60+
https://oshpark.com/shared_projects/iJOnNry7
5261

53-
TODO
62+
TODO: Upload schematics

config.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "rtc.h"
77
#include "transmit.h"
88

9-
#ifdef TRANSMITTER_WIFI
9+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
1010
char const* get_encryption_str(int32_t enc_type);
1111
#endif
1212

@@ -107,6 +107,8 @@ void print_menu() {
107107
Serial.println("[v] Calibrate temperature sensor");
108108
#ifdef TRANSMITTER_WIFI
109109
Serial.println("[w] Setup wifi");
110+
#endif
111+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
110112
Serial.println("[a] List nearby access points");
111113
#endif
112114
Serial.println("[i] Setup Cell ID");
@@ -218,6 +220,8 @@ void enter_configuration() {
218220
print_menu();
219221
break;
220222
}
223+
#endif
224+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
221225
case 'a': {
222226
wl_ap_info_t ap_list[20];
223227
int networkCount = 0;
@@ -389,7 +393,7 @@ void update_last_reading_time(uint32_t timestamp) {
389393
Serial.println("updated last reading time");
390394
}
391395

392-
#ifdef TRANSMITTER_WIFI
396+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
393397
char const* get_encryption_str(int32_t enc_type)
394398
{
395399
// read the encryption type and print out the name:

heatseek_sensor.ino

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <DHT.h>
33
#include <SD.h>
44
#include <SPI.h>
5+
#include "user_config.h"
56
#include "transmit.h"
67
#include "config.h"
78
#include "watchdog.h"

transmit.cpp

+77-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
#include "watchdog.h"
44
#include <SD.h>
55

6-
#ifdef TRANSMITTER_WIFI
6+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
77
AdafruitHTTP http;
88
bool wifiConnected = false;
99
volatile bool response_received = false;
1010
volatile bool transmit_success = false;
1111
#endif
1212

13+
#ifdef HEATSEEK_FEATHER_WIFI_M0
14+
WiFiClient wifiClient;
15+
bool wifiConnected = false;
16+
#endif
17+
1318
#ifdef TRANSMITTER_GSM
1419
#include <avr/dtostrf.h>
1520

@@ -121,7 +126,7 @@
121126
}
122127
#endif
123128

124-
#ifdef TRANSMITTER_WIFI
129+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
125130
void force_wifi_reconnect(void) {
126131
wifiConnected = false;
127132
}
@@ -215,6 +220,76 @@
215220
}
216221
#endif
217222

223+
#ifdef HEATSEEK_FEATHER_WIFI_M0
224+
void force_wifi_reconnect(void) {
225+
if (wifiConnected) {
226+
wifiConnected = false;
227+
WiFi.end();
228+
}
229+
}
230+
231+
void connect_to_wifi() {
232+
WiFi.setPins(8, 7, 4, 2);
233+
234+
Serial.print("Please wait while connecting to:");
235+
Serial.print(CONFIG.data.wifi_ssid);
236+
Serial.println("... ");
237+
238+
int status = WL_IDLE_STATUS;
239+
240+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
241+
status = WiFi.begin(CONFIG.data.wifi_ssid, CONFIG.data.wifi_pass);
242+
243+
while (status != WL_CONNECTED) {
244+
delay(1000);
245+
Serial.println("Establishing connection...");
246+
}
247+
248+
wifiConnected = true;
249+
Serial.println("Connected to WiFi");
250+
251+
Serial.print("SSID: ");
252+
Serial.println(WiFi.SSID());
253+
254+
// print the received signal strength:
255+
long rssi = WiFi.RSSI();
256+
Serial.print("signal strength (RSSI):");
257+
Serial.print(rssi);
258+
Serial.println(" dBm");
259+
260+
watchdog_feed();
261+
}
262+
263+
bool _transmit(float temperature_f, float humidity, float heat_index, uint32_t current_time) {
264+
if (!CONFIG.data.cell_configured || !CONFIG.data.wifi_configured || !CONFIG.data.endpoint_configured) {
265+
Serial.println("cannot send data - not configured");
266+
return false;
267+
}
268+
269+
if (!wifiConnected) { connect_to_wifi(); }
270+
271+
HttpClient client = HttpClient(wifiClient, CONFIG.data.endpoint_domain, 80);
272+
273+
String contentType = "application/x-www-form-urlencoded";
274+
String data = "temp=" + String(temperature_f, 3) + "&humidity=" + String(humidity, 3) + "&heat_index=" + String(heat_index, 3) + "&hub=" + CONFIG.data.hub_id + "&cell=" + CONFIG.data.cell_id + "&time=" + current_time + "&sp=" + CONFIG.data.reading_interval_s + "&cell_version=" + CODE_VERSION;
275+
276+
Serial.print("Posting data: ");
277+
Serial.println(data);
278+
279+
client.post(CONFIG.data.endpoint_path, contentType, data);
280+
281+
int statusCode = client.responseStatusCode();
282+
String response = client.responseBody();
283+
284+
Serial.print("Status code: ");
285+
Serial.println(statusCode);
286+
Serial.print("Response: ");
287+
Serial.println(response);
288+
289+
return statusCode == 200;
290+
}
291+
#endif
292+
218293
typedef struct {
219294
float temperature_f;
220295
float humidity;

transmit.h

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#ifndef TRANSMIT_H
22
#define TRANSMIT_H
33

4-
#define CODE_VERSION "F-1.1.0"
4+
#define CODE_VERSION "F-1.2.0"
55

6-
#ifdef MCU_STM32F205RG
7-
#define TRANSMITTER_WIFI
8-
#else
6+
#include "user_config.h"
7+
8+
#ifdef HEATSEEK_FEATHER_CELL_M0
99
#define TRANSMITTER_GSM
10+
#else
11+
#define TRANSMITTER_WIFI
1012
#endif
1113

12-
#ifdef TRANSMITTER_WIFI
14+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
1315
#include <libmaple/iwdg.h>
1416
#include <adafruit_feather.h>
1517
#include <adafruit_http.h>
@@ -20,6 +22,16 @@
2022
#define TRANSMITS_PER_LOOP 20
2123
#endif
2224

25+
#ifdef HEATSEEK_FEATHER_WIFI_M0
26+
#include <ArduinoHttpClient.h>
27+
#include <WiFi101.h>
28+
29+
#define DHT_DATA A2
30+
#define SD_CS 10
31+
32+
#define TRANSMITS_PER_LOOP 20
33+
#endif
34+
2335
#ifdef TRANSMITTER_GSM
2436
#include "Adafruit_FONA.h"
2537
#include <Adafruit_SleepyDog.h>
@@ -42,5 +54,5 @@ void clear_queued_transmissions();
4254
#ifdef TRANSMITTER_WIFI
4355
void force_wifi_reconnect();
4456
#endif
45-
57+
4658
#endif

user_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//#define HEATSEEK_FEATHER_CELL_M0
2+
#define HEATSEEK_FEATHER_WIFI_M0
3+
//#define HEATSEEK_FEATHER_WIFI_WICED

watchdog.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#include "watchdog.h"
2-
#include "transmit.h"
2+
3+
#if defined(HEATSEEK_FEATHER_WIFI_M0) || defined(TRANSMITTER_GSM)
4+
#include <Adafruit_SleepyDog.h>
5+
#endif
36

47
void watchdog_init() {
5-
#ifdef TRANSMITTER_WIFI
8+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
69
iwdg_init(IWDG_PRE_256, 3500); // 30 second watchdog, 40kHz processor
710
#endif
811

9-
#ifdef TRANSMITTER_GSM
10-
Watchdog.enable(30000);
12+
#if defined(HEATSEEK_FEATHER_WIFI_M0) || defined(TRANSMITTER_GSM)
13+
Watchdog.enable(16000); // 16 seconds (this is the max supported)
1114
#endif
1215
}
1316

1417
void watchdog_feed() {
15-
#ifdef TRANSMITTER_WIFI
18+
#ifdef HEATSEEK_FEATHER_WIFI_WICED
1619
iwdg_feed();
1720
#endif
1821

19-
#ifdef TRANSMITTER_GSM
22+
#if defined(HEATSEEK_FEATHER_WIFI_M0) || defined(TRANSMITTER_GSM)
2023
Watchdog.reset();
2124
#endif
2225
}

watchdog.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef WATCHDOG_H
22
#define WATCHDOG_H
33

4+
#include "transmit.h"
5+
46
void watchdog_init();
57
void watchdog_feed();
68

0 commit comments

Comments
 (0)