softemp

Dependencies:   mbed DHT22 ATParser SerialGPS

Files at this revision

API Documentation at this revision

Comitter:
svupper
Date:
Wed Nov 21 17:33:07 2018 +0000
Parent:
2:f760e8507750
Commit message:
sofmbedtemp

Changed in this revision

ATParser.lib Show annotated file Show diff for this revision Revisions of this file
Sigfox.cpp Show annotated file Show diff for this revision Revisions of this file
Sigfox.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ATParser.lib	Wed Nov 21 17:33:07 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/dahmani_belkacem/code/ATParser/#07049b3aad7a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sigfox.cpp	Wed Nov 21 17:33:07 2018 +0000
@@ -0,0 +1,105 @@
+
+#include "Sigfox.h"
+
+bool Sigfox::ready() {
+    _at->send("AT");
+    return _at->recv("OK");
+}
+
+bool Sigfox::send(const char *data, char* response) {
+    // If require a response add plus in message
+    if(response != NULL) {
+        // Add request response data
+        _at->send("AT$SF=%s,1", data);
+        // Wait response from sigfox after send
+        if(_at->recv("OK")) {
+            // Wait return
+            return _at->recv("RX=%[^\r]", response);
+        }
+        return false;
+    } else {
+        _at->send("AT$SF=%s", data);
+        return _at->recv("OK");
+    }    
+}
+
+/*
+bool Sigfox::send(const char *data) {
+    // If require a response add plus in message
+        // Add request response data
+        _at->send("AT$SF=%s,1", data);
+        // Wait response from sigfox after send
+
+
+  
+   
+}*/
+
+bool Sigfox::setKey(bool type) {
+    _at->send("ATS410=%d", type);
+    return _at->recv("OK");
+}
+
+bool Sigfox::setPower(uint8_t power) {
+    _at->send("ATS302=%d", power);
+    return _at->recv("OK");
+}
+
+bool Sigfox::setPowerMode(uint8_t power) {
+    _at->send("AT$P=%d", power);
+    return _at->recv("OK");
+}
+
+bool Sigfox::saveConfig() {
+    _at->send("AT$WR");
+    return _at->recv("OK");
+}
+
+void Sigfox::wakeup(DigitalInOut sig_rst, float time) {
+    // Wake up sigfox
+    sig_rst.output();
+    sig_rst = 0;
+    wait(time);
+    // Set high impendance the sigfox reset pin
+    sig_rst.input();
+    wait(time);
+}
+
+char *Sigfox::getID() {
+    char buff[8+2];
+    _at->send("AT$I=10");
+    _at->read(buff, 8+2);
+    memcpy(&ID[0],&buff[0],8);
+    return &ID[0];
+}
+
+char *Sigfox::getPAC() {
+    char buff[16+2];
+    _at->send("AT$I=11");
+    _at->read(buff, 16+2);
+    memcpy(&PAC[0],&buff[0],16);
+    return &PAC[0];
+}
+
+float Sigfox::getTemperature() {
+    char buff[6];
+    _at->send("AT$T?");
+    _at->read(buff, 6);
+    buff[5] = 0;
+    return ((double)atoi(buff))/10;
+}
+
+sigfoxvoltage_t Sigfox::getVoltages() {
+    sigfoxvoltage_t volt;
+    char buff[12];
+    _at->send("AT$V?");
+    _at->read(buff, 12);
+    char buff2[5];
+    memset(buff2,0,5);
+    memcpy(buff2, &buff[0], 4);
+    volt.current = ((double)atoi(buff2))/1000;
+    memset(buff2,0,5);
+    memcpy(buff2, &buff[6], 4);
+    volt.last = ((double)atoi(buff2))/1000;
+    return volt;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sigfox.h	Wed Nov 21 17:33:07 2018 +0000
@@ -0,0 +1,69 @@
+/* Copyright (c) 2015 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @section DESCRIPTION
+ *
+ * Send command to Sigfox
+ *
+ */
+#ifndef SIGFOX_H
+#define SIGFOX_H
+
+#include "ATParser.h"
+#include "mbed.h"
+
+// https://www.disk91.com/2016/technology/sigfox/test-of-sigfox-wisol-wssfm10r1-module/
+
+typedef struct _sigfoxvoltage {
+    double current;
+    double last;
+} sigfoxvoltage_t;
+
+class Sigfox
+{
+    private:
+    ATParser *_at;
+    char ID[9];
+    char PAC[17];
+    
+    public:
+    Sigfox(ATParser &at) : _at(&at) {};
+    
+    bool ready();
+    
+    bool send(const char *data, char* response);
+    /**
+     * true = public
+     * false = private
+     */
+    bool setKey(bool type);
+    
+    bool setPower(uint8_t power=15);
+    
+    bool setPowerMode(uint8_t power);
+    
+    void wakeup(DigitalInOut sig_rst, float time=0.2);
+    
+    bool saveConfig();
+    
+    char *getID();
+    
+    char *getPAC();
+    
+    sigfoxvoltage_t getVoltages();
+    
+    float getTemperature();
+};
+
+#endif  /* SIGFOX_H */
\ No newline at end of file