get humidity data and send to LoRa gateway

Dependencies:   mbed X_NUCLEO_IKS01A2

Revision:
5:90900ae27136
Parent:
4:4a012fc4ecc4
--- a/main.cpp	Wed Apr 22 15:00:19 2020 +0000
+++ b/main.cpp	Wed Apr 22 16:20:58 2020 +0000
@@ -15,6 +15,7 @@
 
 static XNucleoIKS01A2* board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
 static HTS221Sensor *ht_sensor = board->ht_sensor;
+char* msgSend[64];
 
 void join_lora_gateway(string eui = "0000000000000001", string ak = "00000000000000000000000000000001", string join_method = "1") {
     pc.printf("Test seriale no pc\r\n");
@@ -78,8 +79,24 @@
     return 0;
 }
 
-void at_send(string port, string msg, string ack = "0") {
-    modem_at_cmd("AT+SEND=" +port+ "," +msg+ "," +ack);
+void at_send(uint8_t port, float hum, uint8_t ack = 0) {
+    char msg[30];
+    char send[64];
+    uint8_t i=0;
+    sprintf(msg,"{\"humidity\":%.2f}", hum);
+    pc.printf(msg);
+    pc.printf("\r\n");
+    pc.printf("Lunghezza messaggio %d",(int)strlen(msg));
+    pc.printf("\r\n");
+    sprintf(send,"AT+SEND=%d,",port);
+    for(i=0;i<strlen(msg);i++)
+    {
+        sprintf(send+11+2*i,"%X",*(msg+i));
+    }
+    sprintf(send+11+2*i,",%d",ack);
+    modem_at_cmd(send);
+    pc.printf(send);
+    pc.printf("\r\nInviato send\r\n");
 }
 
 int main() {
@@ -96,18 +113,7 @@
             pc.printf("Error reading humidity\r\n");
         else {
             pc.printf("Humidity [%%]\t%f\r\n", humidity);
-
-            std::ostringstream ss;
-            ss << humidity;
-        
-            string val = ss.str();
-            for(int i=0; i < val.length(); i++)
-            {
-                sprintf(&val[2*i],"%X", val[i]);
-            }
-        
-            at_send("1515", val);
-        
+            at_send(10, humidity, 0);
         }
         wait(5);
     }