all working version 2.0

Dependencies:   ADS1115 BME280 CronoDot SDFileSystem mbed

Fork of Outdoor_UPAS_v1_2_powerfunction by scott kelleher

Committer:
jelord
Date:
Thu Jan 28 23:05:25 2016 +0000
Revision:
1:9fbb5b665068
Parent:
0:2cb2b2ea316f
Child:
2:88fcbfadec6a
Reliably sending and receiving bytes from my own app... no distinction between messages here

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jelord 0:2cb2b2ea316f 1 #include "mbed.h"
jelord 1:9fbb5b665068 2
jelord 1:9fbb5b665068 3 Serial pc(USBTX, USBRX);
jelord 1:9fbb5b665068 4 //Serial microChannel(PA_9, PA_10); // tx, rx
jelord 1:9fbb5b665068 5 Serial microChannel(D8, D2); // tx, rx
jelord 1:9fbb5b665068 6 Timer t;
jelord 1:9fbb5b665068 7 struct tm tt;
jelord 0:2cb2b2ea316f 8
jelord 1:9fbb5b665068 9 // manual set RTC values
jelord 1:9fbb5b665068 10 int minute =00; // 0-59
jelord 1:9fbb5b665068 11 int hour =21; // 2-23
jelord 1:9fbb5b665068 12 int dayofmonth =6; // 1-31
jelord 1:9fbb5b665068 13 int month =1; // 1-12
jelord 1:9fbb5b665068 14 int year =16; // last 2 digits
jelord 1:9fbb5b665068 15
jelord 1:9fbb5b665068 16 int count,ended,timeout;
jelord 1:9fbb5b665068 17 char timebuf[30];
jelord 1:9fbb5b665068 18 char buf[2024];
jelord 1:9fbb5b665068 19 char snd[1024];
jelord 1:9fbb5b665068 20
jelord 1:9fbb5b665068 21 char ssid[32] = "AdHoc"; // enter WiFi router ssid inside the quotes
jelord 1:9fbb5b665068 22 char pwd [32] = "password"; // enter WiFi router password inside the quotes
jelord 1:9fbb5b665068 23 void gettime(),setRTC();
jelord 1:9fbb5b665068 24 void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate(), YoYo();
jelord 0:2cb2b2ea316f 25
jelord 1:9fbb5b665068 26
jelord 1:9fbb5b665068 27 void pc_recv(void){
jelord 1:9fbb5b665068 28 while(pc.readable()){
jelord 1:9fbb5b665068 29 pc.getc();
jelord 0:2cb2b2ea316f 30 }
jelord 0:2cb2b2ea316f 31 }
jelord 0:2cb2b2ea316f 32
jelord 0:2cb2b2ea316f 33 static uint8_t rx_buf[20];
jelord 0:2cb2b2ea316f 34 static uint8_t rx_len=0;
jelord 1:9fbb5b665068 35 static int haltBLE = 1;
jelord 1:9fbb5b665068 36 static int transmissionValue = 0;
jelord 0:2cb2b2ea316f 37
jelord 0:2cb2b2ea316f 38 void uartMicro(void){
jelord 1:9fbb5b665068 39
jelord 1:9fbb5b665068 40 haltBLE = 2;
jelord 1:9fbb5b665068 41
jelord 0:2cb2b2ea316f 42 while(microChannel.readable()){
jelord 0:2cb2b2ea316f 43 rx_buf[rx_len++] = microChannel.getc();
jelord 1:9fbb5b665068 44 if(rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\0'){
jelord 1:9fbb5b665068 45 wait(0.1);
jelord 1:9fbb5b665068 46 haltBLE = 1;
jelord 1:9fbb5b665068 47 break;
jelord 1:9fbb5b665068 48 }
jelord 0:2cb2b2ea316f 49 }
jelord 1:9fbb5b665068 50 if(haltBLE!=1){
jelord 1:9fbb5b665068 51 for(int i=0; i<rx_len; i++){
jelord 1:9fbb5b665068 52 pc.putc(rx_buf[0]);
jelord 1:9fbb5b665068 53 }
jelord 0:2cb2b2ea316f 54 }
jelord 0:2cb2b2ea316f 55 rx_len = 0;
jelord 0:2cb2b2ea316f 56
jelord 0:2cb2b2ea316f 57 }
jelord 1:9fbb5b665068 58
jelord 1:9fbb5b665068 59
jelord 1:9fbb5b665068 60 int main(){
jelord 1:9fbb5b665068 61
jelord 1:9fbb5b665068 62 // reset=0; //hardware reset for 8266
jelord 1:9fbb5b665068 63 pc.baud(115200); // set what you want here depending on your terminal program speed
jelord 1:9fbb5b665068 64 pc.printf("\f\n\r-------------Startup-------------\n\r");
jelord 1:9fbb5b665068 65 wait(0.5);
jelord 1:9fbb5b665068 66 //reset=1;
jelord 1:9fbb5b665068 67 timeout=2;
jelord 0:2cb2b2ea316f 68
jelord 1:9fbb5b665068 69 pc.attach(pc_recv);
jelord 1:9fbb5b665068 70 microChannel.attach(uartMicro,microChannel.RxIrq);
jelord 1:9fbb5b665068 71 microChannel.baud(115200); // change this to the new ESP8266 baudrate if it is changed at any time.
jelord 0:2cb2b2ea316f 72
jelord 1:9fbb5b665068 73 //uint8_t tempBuf[20] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13};
jelord 1:9fbb5b665068 74 microChannel.printf("$$$");
jelord 1:9fbb5b665068 75 wait(1);
jelord 1:9fbb5b665068 76 microChannel.printf("SN, JakeMicro\r");
jelord 1:9fbb5b665068 77 wait(1);
jelord 1:9fbb5b665068 78 microChannel.printf("A\r");
jelord 1:9fbb5b665068 79 wait(1);
jelord 1:9fbb5b665068 80 microChannel.printf("---");
jelord 0:2cb2b2ea316f 81 wait(1);
jelord 1:9fbb5b665068 82 microChannel.printf("Here is 21 character\n");
jelord 1:9fbb5b665068 83 // continuosly get AP list and IP
jelord 1:9fbb5b665068 84 while(1) {
jelord 1:9fbb5b665068 85 wait(25);
jelord 1:9fbb5b665068 86 uint8_t zero[1] = {0,};
jelord 1:9fbb5b665068 87 microChannel.printf("Here is 20 characr\n");
jelord 1:9fbb5b665068 88 microChannel.putc(zero[0]);
jelord 1:9fbb5b665068 89 //pc.printf("Alive\n");
jelord 1:9fbb5b665068 90 //microChannel.printf("ALIVE");
jelord 0:2cb2b2ea316f 91 }
jelord 0:2cb2b2ea316f 92 }