Manometr mierzący ciśnienie w kołach

Dependencies:   Cayenne-MQTT-mbed mbed TMP36 X_NUCLEO_IDW01M1v2 NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
percu
Date:
Wed Jan 27 23:09:02 2021 +0000
Parent:
5:294a8b1bca28
Commit message:
sw

Changed in this revision

Czujniki.lib Show annotated file Show diff for this revision Revisions of this file
TMP36.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Czujniki.lib	Wed Jan 27 23:09:02 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/percu/code/TMP36/#b28f9b9a8962
--- a/TMP36.lib	Fri Nov 11 18:31:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/zchen311/code/TMP36/#ab3d7d0c34ce
--- a/main.cpp	Fri Nov 11 18:31:11 2016 +0000
+++ b/main.cpp	Wed Jan 27 23:09:02 2021 +0000
@@ -1,22 +1,18 @@
-/**
-* Example app for using the Cayenne MQTT mbed library to send data from a TMP36 sensor. This example uses
-* the X-NUCLEO-IDW01M1 WiFi expansion board via the X_NUCLEO_IDW01M1v2 library.
-*/
-
 #include "MQTTTimer.h"
 #include "CayenneMQTTClient.h"
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
-#include "TMP36.h"
+#include "ABP.h"
+#include "LM35.h"
 
-// WiFi network info.
-char* ssid = "ssid";
-char* wifiPassword = "wifiPassword";
+// Dane do wifi
+char* ssid = "FunBox2-20F4";
+char* wifiPassword = "3129F7A6C2479CC337E77C5D6A";
 
-// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
-char* username = "MQTT_USERNAME";
-char* password = "MQTT_PASSWORD";
-char* clientID = "CLIENT_ID";
+// Dane do Cayenne
+char* username = "a9472990-3ff6-11eb-a2e4-b32ea624e442";
+char* password = "9c7d211eff0e1f0da7d90e036eeaafada2ac5339";
+char* clientID = "28d96ff0-3ff8-11eb-8779-7d56e82df461";
 
 SpwfSAInterface interface(D8, D2); // TX, RX
 MQTTNetwork<SpwfSAInterface> network(interface);
@@ -24,10 +20,6 @@
 
 DigitalOut led1(LED1);
 
-/**
-* Print the message info.
-* @param[in] message The message received from the Cayenne server.
-*/
 void outputMessage(CayenneMQTT::MessageData& message)
 {
     switch (message.topic)  {
@@ -62,44 +54,33 @@
     printf("\n");
 }
 
-/**
-* Handle messages received from the Cayenne server.
-* @param[in] message The message received from the Cayenne server.
-*/
 void messageArrived(CayenneMQTT::MessageData& message)
 {
     int error = 0;
-    // Add code to process the message. Here we just ouput the message data.
     outputMessage(message);
 
     if (message.topic == COMMAND_TOPIC) {
         switch(message.channel) {
         case 0:
-            // Set the onboard LED state
+
             led1 = atoi(message.getValue());
-            // Publish the updated LED state
+        
             if ((error = mqttClient.publishData(DATA_TOPIC, message.channel, NULL, NULL, message.getValue())) != CAYENNE_SUCCESS) {
                 printf("Publish LED state failure, error: %d\n", error);
             }
             break;
         }
         
-        // If this is a command message we publish a response. Here we are just sending a default 'OK' response.
-        // An error response should be sent if there are issues processing the message.
+        
         if ((error = mqttClient.publishResponse(message.id, NULL, message.clientID)) != CAYENNE_SUCCESS) {
             printf("Response failure, error: %d\n", error);
         }
     }
 }
 
-/**
-* Connect to the Cayenne server.
-* @return Returns CAYENNE_SUCCESS if the connection succeeds, or an error code otherwise.
-*/
 int connectClient(void)
 {
     int error = 0;
-    // Connect to the server.
     printf("Connecting to %s:%d\n", CAYENNE_DOMAIN, CAYENNE_PORT);
     while ((error = network.connect(CAYENNE_DOMAIN, CAYENNE_PORT)) != 0) {
         printf("TCP connect failed, error: %d\n", error);
@@ -112,7 +93,7 @@
     }
     printf("Connected\n");
 
-    // Subscribe to required topics.
+    
     if ((error = mqttClient.subscribe(COMMAND_TOPIC, CAYENNE_ALL_CHANNELS)) != CAYENNE_SUCCESS) {
         printf("Subscription to Command topic failed, error: %d\n", error);
     }
@@ -120,29 +101,27 @@
         printf("Subscription to Config topic failed, error:%d\n", error);
     }
 
-    // Send device info. Here we just send some example values for the system info. These should be changed to use actual system data, or removed if not needed.
     mqttClient.publishData(SYS_VERSION_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, CAYENNE_VERSION);
     mqttClient.publishData(SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "mbedDevice");
-    //mqttClient.publishData(SYS_CPU_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "CPU Model");
-    //mqttClient.publishData(SYS_CPU_SPEED_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "1000000000");
 
     return CAYENNE_SUCCESS;
 }
 
-/**
-* Main loop where MQTT code is run.
-*/
 void loop(void)
 {
-    // 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);
+    MQTTTimer timer(1000);
+    LM35 LM35(A1); // Wyłowanie klasy z PINEM A0 odpowiadająca czujnik temperatury LM35 
+ABP ABP(A0); //Wyłowanie klasy z PINEM A0 odpowiadająca czujniki ciśnienia  ABPMANV150PGAA5 HONEYWELL
+double Idealne_cisnienie,bary,ile; // zmienne odpowiadające rózne obliczenia ciśnień 
+int wzorzecP,wzorzecT; // zmienne odpowiadjące za wzrocowe cisnieni i temperature
+wzorzecP=230000;  //Ciśnieni wzorcowe w kole 
+wzorzecT=293;  //Temperatura wzorcowe w kole 
     
     while (true) {
-        // Yield to allow MQTT message processing.
+        Idealne_cisnienie=(((wzorzecP)*(LM35.read()+ 273))/(wzorzecT)); 
+bary=Idealne_cisnienie/100000;
+ile=(bary-ABP.read());
         mqttClient.yield(1000);
-
-        // Check that we are still connected, if not, reconnect.
         if (!network.connected() || !mqttClient.connected()) {
             network.disconnect();
             mqttClient.disconnect();
@@ -153,33 +132,32 @@
             }
         }
 
-        // 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, LM35.read())) != CAYENNE_SUCCESS) {
+                printf("Publish temperature failed, error: %d\n", error);
+        
+            }
+                 if ((error = mqttClient.publishData(DATA_TOPIC,2, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL, ABP.read())) != CAYENNE_SUCCESS) 
+                 { 
+                printf("Publish temperature failed, error: %d\n", error);
+                }
+             if ((error = mqttClient.publishData(DATA_TOPIC, 3, TYPE_BAROMETRIC_PRESSURE, UNIT_HECTOPASCAL,ile)) != 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.
             timer.countdown_ms(5000);
-        }
+            }
     }
 }
 
-/**
-* Main function.
-*/
 int main()
 {   
-    // Initialize the network interface.
-    printf("Initializing interface\n");
+    printf("Ladowanie interfejsu \n");
     interface.connect(ssid, wifiPassword, NSAPI_SECURITY_WPA2);
-
-    // Set the default function that receives Cayenne messages.
     mqttClient.setDefaultMessageHandler(messageArrived);
-
-    // Connect to Cayenne.
     if (connectClient() == CAYENNE_SUCCESS) {
-        // Run main loop.
         loop();
     }
     else {