asdasd
Dependencies: Cayenne-MQTT-mbed mbed X_NUCLEO_IKS01A2 X_NUCLEO_IDW01M1v2 NetworkSocketAPI TMP36
Diff: main.cpp
- Revision:
- 6:8aa852ca98d8
- Parent:
- 5:294a8b1bca28
- Child:
- 7:4265a0d54e46
--- a/main.cpp Fri Nov 11 18:31:11 2016 +0000 +++ b/main.cpp Wed Dec 23 21:46:54 2020 +0000 @@ -8,6 +8,8 @@ #include "MQTTNetworkIDW01M1.h" #include "SpwfInterface.h" #include "TMP36.h" +#include "mbed.h" +#include "XNucleoIKS01A2.h" // WiFi network info. char* ssid = "ssid"; @@ -21,6 +23,11 @@ SpwfSAInterface interface(D8, D2); // TX, RX MQTTNetwork<SpwfSAInterface> network(interface); CayenneMQTT::MQTTClient<MQTTNetwork<SpwfSAInterface>, MQTTTimer> mqttClient(network, username, password, clientID); +// płytka dodatkowa +static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5); +//czujniki +static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor; +static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor; DigitalOut led1(LED1); @@ -137,7 +144,10 @@ // Start the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval. MQTTTimer timer(5000); TMP36 tmpSensor(A5); - + float stopnie,paskal; + char buffer6[32],buffer7[32]; + press_temp->enable(); + press_temp->get_pressure(&stopnie); while (true) { // Yield to allow MQTT message processing. mqttClient.yield(1000); @@ -156,7 +166,7 @@ // Publish some example data every few seconds. This should be changed to send your actual data to Cayenne. if (timer.expired()) { int error = 0; - if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_TEMPERATURE, UNIT_CELSIUS, tmpSensor.read())) != CAYENNE_SUCCESS) { + if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_TEMPERATURE, UNIT_CELSIUS, stopnie)) != CAYENNE_SUCCESS) { printf("Publish temperature failed, error: %d\n", error); } // Restart the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval. @@ -165,13 +175,77 @@ } } -/** -* Main function. -*/ -int main() -{ - // Initialize the network interface. - printf("Initializing interface\n"); + + + + + +//coś do dziesiątek + + + + + +static char *print_double(char* str, double v, int decimalDigits=2) +{ +int i = 1; +int intPart, fractPart +;int len; +char *ptr;/* prepare decimal digits multiplicator */ +for (;decimalDigits!=0; i*=10, decimalDigits--); +/* calculate integer & fractinal parts */ +intPart = (int)v; +fractPart= (int)((v-(double)(int)v)*i);/* fill in integer part */ +sprintf(str, "%i.", intPart);/* prepare fill in of fractional part */ +len = strlen(str); +ptr = &str[len];/* fill in leading fractional zeros */ +for (i/=10;i>1; i/=10, ptr++) +{ + if (fractPart >= i) + { + break; + } + *ptr = '0'; + }/* fill in (rest of) fractional part */ + sprintf(ptr, "%i", fractPart); + return str; + } +int main () +{ +uint8_t id; +float value1, value2; // Deklaracja +char buffer1[32], buffer2[32],buffer3[32],buffer4[32],buffer5[32]; +hum_temp->enable(); +press_temp->enable(); + // hum_temp->get_temperature(&value1); hum_temp->get_humidity(&value3); press_temp->get_pressure(&value2); +printf("Start Programu"); +hum_temp->read_id(&id); +printf("HTS221 temeperatura=0x%X\r\n",id); +press_temp->read_id(&id); +printf("LPS22HB temeperatura=0x%X\r\n",id); +// z czujników i wyświetlanie/ +press_temp->get_pressure(&value1); +printf("Cisnie: %7s hPa\r\n ", print_double(buffer1, value1)); +press_temp->get_temperature(&value2); +printf("Temp: %7s C\r\n ", print_double(buffer2, value2)); +double x,bary,ile;// Cisnie w kole zadane +int wzorzecP,wzorzecT; +wzorzecP=230000; +wzorzecT=293; +x=(((wzorzecP)*(value2+ 273))/(wzorzecT)); +bary=x/100000; +ile=(bary-(value1/1000)); +printf("Ile ma byc w kole? %7s B\r\n ", print_double(buffer3,bary)); +printf("Ilejest w kole? %7s B\r\n ", print_double(buffer1,value1/1000)); +if ((value1/1000)>bary) +{ +printf("Upusc %7s B\r\n ", print_double(buffer5,ile )); +} +else if ((value1/1000)<bary) +{ + printf("dobij %7s B\r\n ", print_double(buffer5,ile )); + } + printf("Initializing interface\n"); interface.connect(ssid, wifiPassword, NSAPI_SECURITY_WPA2); // Set the default function that receives Cayenne messages. @@ -194,3 +268,4 @@ return 0; } + \ No newline at end of file