NRF: receive, ntp, Data to Sd-card working
Dependencies: F7_Ethernet mbed BSP_DISCO_F746NG Test_Mainboard SDFileSystem RF24
main.cpp
- Committer:
- leo44
- Date:
- 2021-06-08
- Revision:
- 0:d984976f1f1c
- Child:
- 1:6210d492bda7
File content as of revision 0:d984976f1f1c:
#include "mbed.h" #include "SDFileSystem.h" #include "stdio.h" #include "rtos.h" #include "EthernetInterface.h" #include "NTPClient.h" EthernetInterface eth; DigitalOut myled(LED1); SDFileSystem sd("sd"); // trim '\n' void ntrim(char *str) { int i; for (i = 0; str[i] != 0; ++i); if (i > 0 && str[i - 1] == '\n') str[i - 1] = 0; } int main() { int temp_array[1]; // Nur zum Test temp_array[0]= 123; temp_array[1]= 124; sd.mount(); FILE *fp; NTPClient ntp; char buff[64]; if(eth.init()!=0) //for DHCP Server { //if(eth.init(IP,MASK,GATEWAY)!=0) { //for Static IP Address printf("EthernetInterface Initialize Error \r\n"); while (1) { } } if(eth.connect()!=0) { printf("EthernetInterface Connect Error \r\n"); while (1) { } } int x; for (x=1; x<6;x++){ fp = fopen("/sd/test.txt", "a"); if (fp == NULL) { printf("open error!!\r\n"); while(1); } //////////////////////////////////////// Ethernet connection for timestamp//////////////////////////////////////////////////////////////// printf("Durchlauf\n"); // printf("IP Address is %s\r\n", eth.getIPAddress()); // printf("NetMask is %s\r\n", eth.getNetworkMask()); // printf("Gateway Address is %s\r\n", eth.getGateway()); // printf("Ethernet Setup OK\r\n"); // printf("Getting time, 10s timeout. \r\n"); wait(1); if (ntp.setTime("0.uk.pool.ntp.org") == 0) { time_t ctTime; ctTime = time(NULL); fprintf(fp,"Time:%s \r", ctime(&ctTime)); fprintf(fp,"Temp:%i; ", temp_array[0]); printf("Hole Uhrzeit\n"); } else { printf("Error getting time \r\n"); } fclose (fp); } // for end fp = fopen("/sd/test.txt", "r"); if (fp == NULL) { printf("open error!!\r\n"); while(1); } // read text file char buf[1024]; while (fgets(buf, sizeof(buf), fp) != NULL) { ntrim(buf); printf("%s\r\n", buf); } // file close fclose(fp); }