![](/media/cache/profiles/c19a46c712c75b70a137f619a0916436.jpg.50x50_q85.png)
Skeleton program for Federico's 4YP project.
Dependencies: WebSocketClient WiflyInterface mbed messages
Fork of IoT_Ex by
Diff: source/globals.cpp
- Revision:
- 10:e8b66718a103
- Parent:
- 8:5afd599875e4
--- a/source/globals.cpp Tue Nov 29 12:22:14 2016 +0000 +++ b/source/globals.cpp Tue Nov 29 15:02:01 2016 +0000 @@ -32,8 +32,9 @@ #include "mbed.h" #include "globals.h" +#include "pwm.h" -//#define DEBUG +#define DEBUG #define INFOMESSAGES #define WARNMESSAGES #define ERRMESSAGES @@ -51,8 +52,16 @@ int SendCounter = 0; extern int IoT_ID = 0; float TempSensor = 0.0f; +float VoltageMeasurement = 0.0f; +float CurrentMeasurement = 0.0f; +float PwmPeriod_us = 20.0f; +float Duty_us = 10.0f; char* wifissid = "SC"; char* wifipassword = "smartcellshield"; +DigitalOut db(PC_10); +AnalogIn VoltageSensor(VOLTAGE_SENSOR_PIN); +AnalogIn CurrentSensor(CURRENT_SENSOR_PIN); + // Wifily interface declaration: WiflyInterface eth(D8, D2, D6, LED1, wifissid, wifipassword, WPA2); @@ -104,7 +113,7 @@ int intresult; if(IotStatus.CheckFlag(SF_SERVERCONNECTED)){ - sprintf(msg_buffer, "%d,%d,%.5f", IoT_ID, SendCounter,TempSensor); + sprintf(msg_buffer, "%d,%d,%.5f,%.5f,%.5f,%.5f", IoT_ID, SendCounter,TempSensor, VoltageMeasurement, CurrentMeasurement, PwmPeriod_us); INFO("Sending: %s", msg_buffer); // When this line is commented out, the mbed never tries to reconnect to the server after one try. SUPER. Keeping this here also uses precious CPU time intresult = ws.send(msg_buffer); }else{ @@ -170,6 +179,10 @@ // Get one more value: sscanf(msg_buffer2, "%f", value); } + if(*wifi_cmd == CV_PWM_PERIOD_US_CMD){ + // Get one more value: + sscanf(msg_buffer2, "%f", value); + } }else if(resp == -1){ // Connection to the server is lost: IotStatus.ClearFlag(SF_SERVERCONNECTED); @@ -185,13 +198,19 @@ void ModifyVariable(unsigned int wifi_var, float wifi_data){ // modifies something in the SCS Controller: switch(wifi_var){ - case CV_LED: + case CV_LED_WIFI_CMD: if(wifi_data > 0){ Led = 1; }else{ Led = 0; } break; + case CV_PWM_PERIOD_US_CMD: + DBG("wifi_data: %.3f", wifi_data); + PwmPeriod_us = wifi_data; + SetPWMPeriodAndDuty_us(PwmPeriod_us); + break; + default: break;