test
Dependencies: MbedJSONValue DISCO_L475VG_IOT01A_wifi mbed-http
Revision 0:065178c282bd, committed 2019-01-01
- Comitter:
- Eason0505
- Date:
- Tue Jan 01 11:48:52 2019 +0000
- Commit message:
- test
Changed in this revision
diff -r 000000000000 -r 065178c282bd DISCO_L475VG_IOT01A_wifi.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DISCO_L475VG_IOT01A_wifi.lib Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/DISCO_L475VG_IOT01A_wifi/#c61a93635433
diff -r 000000000000 -r 065178c282bd MbedJSONValue.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MbedJSONValue.lib Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/samux/code/MbedJSONValue/#10a99cdf7846
diff -r 000000000000 -r 065178c282bd ServoMove.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ServoMove.cpp Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,38 @@ +#include "ServoMove.h" +PwmOut servo(PA_6); +Serial pc1(USBTX, USBRX); + +void ServoConvert(double cnv) +{ + if (cnv > 144) { + servo.pulsewidth_us(1000); //0deg + pc1.printf("cnv1 =%f\n\r",cnv); + } else if(cnv >108 && cnv <144) { + servo.pulsewidth_us(1100); + pc1.printf("cnv2 =%f\n\r",cnv); + } else if (cnv >72 && cnv <108) { + servo.pulsewidth_us(1200); + pc1.printf("cnv3 =%f\n\r",cnv); + } else if (cnv > 36&& cnv <72) { + servo.pulsewidth_us(1300); + pc1.printf("cnv4 =%f\n\r",cnv); + } else if(cnv > 0&& cnv <36) { + servo.pulsewidth_us(1400); + pc1.printf("cnv5 =%f\n\r",cnv); + } else if(cnv > -36&& cnv <0) { + servo.pulsewidth_us(1500); + pc1.printf("cnv6 =%f\n\r",cnv); + } else if(cnv > -72&& cnv <-36) { + servo.pulsewidth_us(1600); + pc1.printf("cnv7 =%f\n\r",cnv); + } else if(cnv > -108&& cnv <-72) { + servo.pulsewidth_us(1700); + pc1.printf("cnv8 =%f\n\r",cnv); + } else if(cnv > -144&& cnv <-108) { + servo.pulsewidth_us(1800); + pc1.printf("cnv9 =%f\n\r",cnv); + } else if(cnv > -180&& cnv <-144) { + servo.pulsewidth_us(1900); + pc1.printf("cnv10 =%f\n\r",cnv); + } +} \ No newline at end of file
diff -r 000000000000 -r 065178c282bd ServoMove.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ServoMove.h Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,6 @@ +#ifndef SERVOMOVE_H +#define SERVOMOVE_H +#include "mbed.h" +extern PwmOut servo; +void ServoConvert(double cnv); // function prototype +#endif \ No newline at end of file
diff -r 000000000000 -r 065178c282bd US100.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/US100.cpp Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,29 @@ +#include "US100.h" +#include "mbed.h" +US100::US100(PinName t, PinName e) : trig(t), echo(e) {} +// Trigger Echo +// ______ _____________,,,,,,,,, +// ____| 10us |_________| 150us-25ms, or 38ms if no obstacle +// +//return echo duration in us (refer to digram above) +int US100::echo_duration() +{ + timer.reset(); + trig = 0; + wait_us(10); + trig = 1; + wait_us(10); + trig = 0; + while(echo == 0); + timer.start(); + while(echo == 1); + timer.stop(); + return timer.read_us(); +} + +int US100::distance() +{ +int duration = echo_duration(); +int distacne_mm = duration*0.34/2/10; +return distacne_mm; +} \ No newline at end of file
diff -r 000000000000 -r 065178c282bd US100.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/US100.h Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,16 @@ +#ifndef US100_H +#define US100_H +#include "mbed.h" +class US100 +{ +public: + US100(PinName t, PinName e); + int echo_duration(); + int distance(); +private: + DigitalOut trig; + DigitalIn echo; + Timer timer; +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r 065178c282bd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,102 @@ +#include "mbed.h" +#include "wifi.h" +#include "US100.h" +#include "NetworkInterface.h" +#include "ISM43362Interface.h" +#include "http_request.h" +#include "MbedJSONValue.h" +#include <string> + +/* Private defines -----------------------------------------------------------*/ +#define WIFI_WRITE_TIMEOUT 10000 +#define WIFI_READ_TIMEOUT 10000 +#define CONNECTION_TRIAL_MAX 10 + +/* Private typedef------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ +/* Private variables ---------------------------------------------------------*/ +Serial pc(SERIAL_TX, SERIAL_RX); +ISM43362Interface wifi(MBED_CONF_APP_WIFI_SPI_MOSI, MBED_CONF_APP_WIFI_SPI_MISO, MBED_CONF_APP_WIFI_SPI_SCLK, MBED_CONF_APP_WIFI_SPI_NSS, MBED_CONF_APP_WIFI_RESET, MBED_CONF_APP_WIFI_DATAREADY, MBED_CONF_APP_WIFI_WAKEUP, false); +uint8_t MAC_Addr[6]; +uint8_t IP_Addr[4]; + +// RoLa +DigitalOut M0(PD_14); +DigitalOut M1(PB_0); +Serial uart(PA_0, PA_1);//TX4,RX4 +string inputdata; +double cnv; + +// Interval(second) to do tasking &sensing +const int INTERVAL = 1; +// Distance sensor +US100 sensor(PC_3, PC_4); +// Select network interface +NetworkInterface* network = &wifi; + +int main() +{ + + pc.baud(9600); + + printf("\n"); + printf("************************************************************\n"); + printf("*** IoT Final Project - TSENG, I-SHENG ***\n"); + printf("************************************************************\n"); + + /*Initialize WIFI module */ + if(WIFI_Init() == WIFI_STATUS_OK) { + printf("> WIFI Module Initialized.\n"); + if(WIFI_GetMAC_Address(MAC_Addr) == WIFI_STATUS_OK) { + printf("> es-wifi module MAC Address : %X:%X:%X:%X:%X:%X\n", + MAC_Addr[0], + MAC_Addr[1], + MAC_Addr[2], + MAC_Addr[3], + MAC_Addr[4], + MAC_Addr[5]); + } else { + printf("> ERROR : CANNOT get MAC address\n"); + } + + if( WIFI_Connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, WIFI_ECN_WPA2_PSK) == WIFI_STATUS_OK) { + printf("> es-wifi module connected \n"); + if(WIFI_GetIP_Address(IP_Addr) == WIFI_STATUS_OK) { + printf("> es-wifi module got IP Address : %d.%d.%d.%d\n", + IP_Addr[0], + IP_Addr[1], + IP_Addr[2], + IP_Addr[3]); + } else { + printf("> ERROR : es-wifi module CANNOT get IP address\n"); + } + } else { + printf("> ERROR : es-wifi module NOT connected\n"); + } + } else { + printf("> ERROR : WIFI Module cannot be initialized.\n"); + } + while(1){ + char c[] = ""; + int d = sensor.distance(); + sprintf(c, "%d", d); + printf("Distance = %d \n", d); + + char body[] = "{\"result\":"; + char body_1[] = "}"; + strcat(body,c); + strcat(body,body_1); + + HttpRequest* POST_request = new HttpRequest(network, HTTP_POST, "http://140.115.111.187:8080/Ray/v1.0/Datastreams(1)/Observations"); + POST_request->set_header("Content-Type", "application/json"); + HttpResponse* response = POST_request->send(body, strlen(body)); + printf("HTTP POST sending...\n"); + // if response is NULL, check response->get_error() + + printf("status is %d - %s\n", response->get_status_code(), response->get_status_message()); + printf("body is:\n%s\n", response->get_body_as_string().c_str()); + + delete POST_request; // also clears out the response + wait(INTERVAL); + } +} \ No newline at end of file
diff -r 000000000000 -r 065178c282bd mbed-http.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-http.lib Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/sandbox/code/mbed-http/#fa4d71265625
diff -r 000000000000 -r 065178c282bd mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6
diff -r 000000000000 -r 065178c282bd mbed_app.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,83 @@ +{ + "config": { + "wifi-shield": { + "help": "Options are internal, WIFI_IDW0XX1", + "value": "internal" + }, + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"Eason503\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"103302507\"" + }, + "wifi-tx": { + "help": "TX pin for serial connection to external device", + "value": "D1" + }, + "wifi-rx": { + "help": "RX pin for serial connection to external device", + "value": "D0" + }, + "wifi-spi_miso": { + "help": "SPI-MISO connection to external device", + "value": "PC_11" + }, + "wifi-spi_mosi": { + "help": "SPI-MOSI connection to external device", + "value": "PC_12" + }, + "wifi-spi_sclk": { + "help": "SPI-CLOCK connection to external device", + "value": "PC_10" + }, + "wifi-spi_nss": { + "help": "SPI chip select of external device", + "value": "PE_0" + }, + "wifi-reset": { + "help": "WIFI module reset pin", + "value": "PE_8" + }, + "wifi-dataready": { + "help": "WIFI module data ready pin", + "value": "PE_1" + }, + "wifi-wakeup": { + "help": "WIFI module wakeup pin", + "value": "PB_12" + } + }, + "target_overrides": { + "*": { + "platform.stdio-convert-newlines": true + }, + "NUCLEO_L476RG": { + "wifi-tx": "D8", + "wifi-rx": "D2" + }, + "NUCLEO_F401RE": { + "wifi-tx": "D8", + "wifi-rx": "D2" + }, + "DISCO_L475VG_IOT1A": { + "wifi-spi_miso": "PC_11", + "wifi-spi_mosi": "PC_12", + "wifi-spi_sclk": "PC_10", + "wifi-spi_nss": "PE_0", + "wifi-reset": "PE_8", + "wifi-dataready": "PE_1", + "wifi-wakeup": "PB_12" + }, + "DISCO_F413ZH": { + "wifi-spi_miso": "PB_4", + "wifi-spi_mosi": "PB_5", + "wifi-spi_sclk": "PB_12", + "wifi-spi_nss": "PG_11", + "wifi-reset": "PH_1", + "wifi-dataready": "PG_12", + "wifi-wakeup": "PB_15" + } + } +}
diff -r 000000000000 -r 065178c282bd mbed_app_ism43362.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app_ism43362.json Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,86 @@ +{ + "config": { + "wifi-shield": { + "help": "Options are internal, WIFI_ESP8266, WIFI_IDW0XX1", + "value": "internal" + }, + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"Eason503\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"103302507\"" + }, + "wifi-tx": { + "help": "TX pin for serial connection to external device", + "value": "D1" + }, + "wifi-rx": { + "help": "RX pin for serial connection to external device", + "value": "D0" + }, + "wifi-spi_miso": { + "help": "SPI-MISO connection to external device", + "value": "PC_11" + }, + "wifi-spi_mosi": { + "help": "SPI-MOSI connection to external device", + "value": "PC_12" + }, + "wifi-spi_sclk": { + "help": "SPI-CLOCK connection to external device", + "value": "PC_10" + }, + "wifi-spi_nss": { + "help": "SPI chip select of external device", + "value": "PE_0" + }, + "wifi-reset": { + "help": "WIFI module reset pin", + "value": "PE_8" + }, + "wifi-dataready": { + "help": "WIFI module data ready pin", + "value": "PE_1" + }, + "wifi-wakeup": { + "help": "WIFI module wakeup pin", + "value": "PB_12" + } + }, + "target_overrides": { + "*": { + "platform.stdio-convert-newlines": true + }, + "UBLOX_EVK_ODIN_W2": { + "target.device_has": ["EMAC"] + }, + "NUCLEO_L476RG": { + "wifi-tx": "D8", + "wifi-rx": "D2" + }, + "NUCLEO_F401RE": { + "wifi-tx": "D8", + "wifi-rx": "D2" + }, + "DISCO_L475VG_IOT1A": { + "wifi-spi_miso": "PC_11", + "wifi-spi_mosi": "PC_12", + "wifi-spi_sclk": "PC_10", + "wifi-spi_nss": "PE_0", + "wifi-reset": "PE_8", + "wifi-dataready": "PE_1", + "wifi-wakeup": "PB_12" + }, + "DISCO_F413ZH": { + "wifi-spi_miso": "PB_4", + "wifi-spi_mosi": "PB_5", + "wifi-spi_sclk": "PB_12", + "wifi-spi_nss": "PG_11", + "wifi-reset": "PH_1", + "wifi-dataready": "PG_12", + "wifi-wakeup": "PB_15" + } + } +}
diff -r 000000000000 -r 065178c282bd wifi-ism43362.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifi-ism43362.lib Tue Jan 01 11:48:52 2019 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/wifi-ism43362/#e4ecc27e87d96072f7df62a25ef007986dc95c4e