LoRa Access Point 1.5.2018

Dependencies:   mbed ds3231 SX1276Lib_LoRa_Access_Point

Committer:
lukas_formanek
Date:
Thu Mar 28 09:55:48 2019 +0000
Revision:
10:e62222c46ee9
Parent:
9:28e272b6b018
Child:
11:376bfcdda0d4
28.3.2019 working SD,RTC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukas_formanek 0:ea088908ad26 1 #include "mbed.h"
lukas_formanek 0:ea088908ad26 2 #include "RFM95W.h"
lukas_formanek 0:ea088908ad26 3 #include "ESP8266.h"
lukas_formanek 1:7543af31b91f 4 #include "Board.h"
lukas_formanek 10:e62222c46ee9 5 #include "SD.h"
lukas_formanek 0:ea088908ad26 6
lukas_formanek 10:e62222c46ee9 7 //DS3231 rtc(D14, D15);
lukas_formanek 10:e62222c46ee9 8 //time_t epoch_time = 0;
lukas_formanek 10:e62222c46ee9 9
lukas_formanek 10:e62222c46ee9 10 int hour;
lukas_formanek 10:e62222c46ee9 11 int minute;
lukas_formanek 10:e62222c46ee9 12 int second;
lukas_formanek 10:e62222c46ee9 13
lukas_formanek 10:e62222c46ee9 14 int dayOfWeek;
lukas_formanek 10:e62222c46ee9 15 int date;
lukas_formanek 10:e62222c46ee9 16 int month;
lukas_formanek 10:e62222c46ee9 17 int year;
lukas_formanek 10:e62222c46ee9 18
lukas_formanek 10:e62222c46ee9 19
lukas_formanek 10:e62222c46ee9 20
lukas_formanek 10:e62222c46ee9 21 int main()
lukas_formanek 10:e62222c46ee9 22 {
lukas_formanek 10:e62222c46ee9 23 DS3231 rtc(D14,D15);
lukas_formanek 10:e62222c46ee9 24
lukas_formanek 10:e62222c46ee9 25
lukas_formanek 10:e62222c46ee9 26 rtc.setI2Cfrequency(400000);
lukas_formanek 10:e62222c46ee9 27 //RTC.writeRegister(DS3231_Aging_Offset,0); // uncomment to set Aging Offset 1LSB = approx. 0.1 ppm according from datasheet = 0.05 ppm @ 21 °C from my measurments
lukas_formanek 10:e62222c46ee9 28 rtc.convertTemperature();
lukas_formanek 10:e62222c46ee9 29 int reg=rtc.readRegister(DS3231_Aging_Offset);
lukas_formanek 10:e62222c46ee9 30 if (reg>127)
lukas_formanek 10:e62222c46ee9 31 {reg=reg-256;}
lukas_formanek 10:e62222c46ee9 32
lukas_formanek 10:e62222c46ee9 33 pc.printf("Aging offset : %i\r\n",reg);
lukas_formanek 10:e62222c46ee9 34 pc.printf("OSF flag : %i",rtc.OSF());
lukas_formanek 10:e62222c46ee9 35 pc.printf("\r\n");
lukas_formanek 10:e62222c46ee9 36 /*
lukas_formanek 10:e62222c46ee9 37 rtc.readDate(&date,&month,&year);
lukas_formanek 10:e62222c46ee9 38 pc.printf("date : %02i-%02i-%02i",date,month,year);
lukas_formanek 10:e62222c46ee9 39 pc.printf("\r\n");
lukas_formanek 10:e62222c46ee9 40
lukas_formanek 10:e62222c46ee9 41 //RTC.setTime(19,48,45); // uncomment to set time
lukas_formanek 10:e62222c46ee9 42
lukas_formanek 10:e62222c46ee9 43 rtc.readTime(&hour,&minute,&second);
lukas_formanek 10:e62222c46ee9 44 pc.printf("time : %02i:%02i:%02i",hour,minute,second);
lukas_formanek 10:e62222c46ee9 45 pc.printf("\r\n");
lukas_formanek 10:e62222c46ee9 46
lukas_formanek 10:e62222c46ee9 47 //RTC.setDate(6,22,12,2012); // uncomment to set date
lukas_formanek 10:e62222c46ee9 48
lukas_formanek 10:e62222c46ee9 49 rtc.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second);
lukas_formanek 10:e62222c46ee9 50 pc.printf("date time : %i / %02i-%02i-%02i %02i:%02i:%02i",dayOfWeek,date,month,year,hour,minute,second);
lukas_formanek 10:e62222c46ee9 51 pc.printf("\r\n");
lukas_formanek 10:e62222c46ee9 52
lukas_formanek 10:e62222c46ee9 53 pc.printf("temperature :%6.2f",rtc.readTemp());
lukas_formanek 10:e62222c46ee9 54 pc.printf("\r\n");
lukas_formanek 10:e62222c46ee9 55 */
lukas_formanek 10:e62222c46ee9 56 wifi.Init();
lukas_formanek 10:e62222c46ee9 57 bt.Init();
lukas_formanek 10:e62222c46ee9 58 rfm.Init();
lukas_formanek 10:e62222c46ee9 59 while(1)
lukas_formanek 10:e62222c46ee9 60 {
lukas_formanek 10:e62222c46ee9 61 wifi.CheckSettings();
lukas_formanek 10:e62222c46ee9 62 rtc.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second);
lukas_formanek 10:e62222c46ee9 63 snprintf(actual_time, 30, "%02i.%02i.%02i %02i:%02i:%02i |",date,month,year,hour,minute,second);
lukas_formanek 10:e62222c46ee9 64 // pc.printf("%02i.%02i.%02i %02i:%02i:%02i\r\n",date,month,year,hour,minute,second);
lukas_formanek 10:e62222c46ee9 65 wait(0.5);
lukas_formanek 10:e62222c46ee9 66 }
lukas_formanek 10:e62222c46ee9 67 }
lukas_formanek 10:e62222c46ee9 68
lukas_formanek 10:e62222c46ee9 69 /*
lukas_formanek 5:19b34c4d27a1 70 int main()
lukas_formanek 5:19b34c4d27a1 71 {
lukas_formanek 0:ea088908ad26 72 wifi.Init();
lukas_formanek 0:ea088908ad26 73 bt.Init();
lukas_formanek 0:ea088908ad26 74 rfm.Init();
lukas_formanek 9:28e272b6b018 75 // SDcard.Init();
lukas_formanek 10:e62222c46ee9 76 // Ds3231 rtc(D14, D15);
lukas_formanek 10:e62222c46ee9 77
lukas_formanek 0:ea088908ad26 78 while(1) {
lukas_formanek 0:ea088908ad26 79 wifi.CheckSettings();
lukas_formanek 10:e62222c46ee9 80 epoch_time = rtc.get_epoch();
lukas_formanek 10:e62222c46ee9 81 // pc.printf("\nTime as a basic string = %s \r\n", ctime(&epoch_time));
lukas_formanek 10:e62222c46ee9 82 wait(0.5);
lukas_formanek 8:5d99fbf255d6 83 // rfm.WriteDataToSDcard();
lukas_formanek 0:ea088908ad26 84 }
lukas_formanek 0:ea088908ad26 85 }
lukas_formanek 10:e62222c46ee9 86 */
lukas_formanek 10:e62222c46ee9 87
lukas_formanek 10:e62222c46ee9 88 /*
lukas_formanek 10:e62222c46ee9 89 int main()
lukas_formanek 10:e62222c46ee9 90 {
lukas_formanek 10:e62222c46ee9 91 time_t time;
lukas_formanek 10:e62222c46ee9 92 while(1)
lukas_formanek 10:e62222c46ee9 93 {
lukas_formanek 10:e62222c46ee9 94 epoch_time = rtc.get_epoch();
lukas_formanek 10:e62222c46ee9 95 pc.printf("\nTime as a basic string = %s \r\n", ctime(&epoch_time));
lukas_formanek 10:e62222c46ee9 96 wait(1);
lukas_formanek 10:e62222c46ee9 97 }
lukas_formanek 10:e62222c46ee9 98
lukas_formanek 10:e62222c46ee9 99 }
lukas_formanek 10:e62222c46ee9 100 */
lukas_formanek 10:e62222c46ee9 101
lukas_formanek 10:e62222c46ee9 102
lukas_formanek 10:e62222c46ee9 103 /*
lukas_formanek 10:e62222c46ee9 104 int main(void)
lukas_formanek 10:e62222c46ee9 105 {
lukas_formanek 10:e62222c46ee9 106 wifi.Init();
lukas_formanek 10:e62222c46ee9 107 bt.Init();
lukas_formanek 10:e62222c46ee9 108 rfm.Init();
lukas_formanek 10:e62222c46ee9 109 // SDcard.Init();
lukas_formanek 10:e62222c46ee9 110 // sd.mount();
lukas_formanek 10:e62222c46ee9 111 pc.printf("Start! \r\n");
lukas_formanek 10:e62222c46ee9 112 // mon();
lukas_formanek 10:e62222c46ee9 113 // create_file();
lukas_formanek 10:e62222c46ee9 114 // init_card();
lukas_formanek 10:e62222c46ee9 115
lukas_formanek 10:e62222c46ee9 116 //rtc object
lukas_formanek 10:e62222c46ee9 117 Ds3231 rtc(D14, D15);
lukas_formanek 10:e62222c46ee9 118
lukas_formanek 10:e62222c46ee9 119 time_t epoch_time;
lukas_formanek 10:e62222c46ee9 120
lukas_formanek 10:e62222c46ee9 121 //DS3231 rtc variables
lukas_formanek 10:e62222c46ee9 122
lukas_formanek 10:e62222c46ee9 123 //default, use bit masks in ds3231.h for desired operation
lukas_formanek 10:e62222c46ee9 124 // ds3231_cntl_stat_t rtc_control_status = {0,0};
lukas_formanek 10:e62222c46ee9 125 // ds3231_time_t rtc_time;
lukas_formanek 10:e62222c46ee9 126 // ds3231_calendar_t rtc_calendar;
lukas_formanek 10:e62222c46ee9 127
lukas_formanek 10:e62222c46ee9 128 // rtc.set_cntl_stat_reg(rtc_control_status);
lukas_formanek 10:e62222c46ee9 129 char buffer[32];
lukas_formanek 10:e62222c46ee9 130 while(1)
lukas_formanek 10:e62222c46ee9 131 {
lukas_formanek 10:e62222c46ee9 132 // FILE *myLogFile;
lukas_formanek 10:e62222c46ee9 133 // pc.printf("%c[2J", ESC); //clear screen
lukas_formanek 10:e62222c46ee9 134 // pc.printf("%c[H", ESC); //move cursor to Home
lukas_formanek 10:e62222c46ee9 135
lukas_formanek 10:e62222c46ee9 136 //new epoch time fx
lukas_formanek 10:e62222c46ee9 137 epoch_time = rtc.get_epoch();
lukas_formanek 10:e62222c46ee9 138
lukas_formanek 10:e62222c46ee9 139 pc.printf("\nTime as seconds since January 1, 1970 = %d\r\n", epoch_time);
lukas_formanek 10:e62222c46ee9 140
lukas_formanek 10:e62222c46ee9 141 pc.printf("\nTime as a basic string = %s \r\n", ctime(&epoch_time));
lukas_formanek 10:e62222c46ee9 142
lukas_formanek 10:e62222c46ee9 143 strftime(buffer, 32, "%I:%M %p\n", localtime(&epoch_time));
lukas_formanek 10:e62222c46ee9 144 pc.printf("\nTime as a custom formatted string = %s \r\n", buffer);
lukas_formanek 10:e62222c46ee9 145
lukas_formanek 10:e62222c46ee9 146 if (myLogFile)
lukas_formanek 10:e62222c46ee9 147 fclose(myLogFile);
lukas_formanek 10:e62222c46ee9 148 myLogFile = fopen("/sd/DATA_LOG.txt", "a");
lukas_formanek 10:e62222c46ee9 149 pc.printf("try to open\r\n");
lukas_formanek 10:e62222c46ee9 150 if (myLogFile == NULL)
lukas_formanek 10:e62222c46ee9 151 {
lukas_formanek 10:e62222c46ee9 152 pc.printf("ERROR: failed to open the log file for writing!\r\n");
lukas_formanek 10:e62222c46ee9 153 }
lukas_formanek 10:e62222c46ee9 154 else
lukas_formanek 10:e62222c46ee9 155 {
lukas_formanek 10:e62222c46ee9 156 fprintf(myLogFile," %s" ,ctime(&epoch_time));
lukas_formanek 10:e62222c46ee9 157 // fclose(myLogFile);
lukas_formanek 10:e62222c46ee9 158 // free(myLogFile);
lukas_formanek 10:e62222c46ee9 159 }
lukas_formanek 10:e62222c46ee9 160 fclose(myLogFile);
lukas_formanek 10:e62222c46ee9 161
lukas_formanek 10:e62222c46ee9 162 wait(2);
lukas_formanek 10:e62222c46ee9 163 }
lukas_formanek 10:e62222c46ee9 164 }
lukas_formanek 10:e62222c46ee9 165
lukas_formanek 10:e62222c46ee9 166 */
lukas_formanek 10:e62222c46ee9 167