ruche

Dependencies:   ATParser DHT22 SerialGPS Sigfox mbed

Fork of Nucleo_SerialGPS_to_PC by hime hime

Files at this revision

API Documentation at this revision

Comitter:
dahmani_belkacem
Date:
Fri Feb 02 10:00:12 2018 +0000
Parent:
1:297aba9a5830
Commit message:
Ruche connect?e

Changed in this revision

ATParser.lib Show diff for this revision Revisions of this file
DS1820/DS1820.cpp Show annotated file Show diff for this revision Revisions of this file
DS1820/DS1820.h Show annotated file Show diff for this revision Revisions of this file
Sigfox.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 297aba9a5830 -r f760e8507750 ATParser.lib
--- a/ATParser.lib	Wed Jan 17 14:34:05 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/dahmani_belkacem/code/ATParser/#07049b3aad7a
diff -r 297aba9a5830 -r f760e8507750 DS1820/DS1820.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1820/DS1820.cpp	Fri Feb 02 10:00:12 2018 +0000
@@ -0,0 +1,396 @@
+#include "DS1820.h"
+#include "mbed.h"
+
+// Global variables shared between all DS1820 objects
+bool DS1820_done_flag;
+int  DS1820_last_descrepancy;
+char DS1820_search_ROM[8];
+
+
+DS1820::DS1820 (PinName data_pin, PinName power_pin) : _datapin(data_pin), _parasitepin(power_pin) {
+    int byte_counter;
+
+    _parasite_power = true;
+    for(byte_counter=0;byte_counter<8;byte_counter++)
+        ROM[byte_counter] = 0xFF;
+    for(byte_counter=0;byte_counter<9;byte_counter++)
+        RAM[byte_counter] = 0x00;
+}
+DS1820::DS1820 (PinName data_pin) : _datapin(data_pin), _parasitepin(NC) {
+    int byte_counter;
+    _parasite_power = false;
+    for(byte_counter=0;byte_counter<8;byte_counter++)
+        ROM[byte_counter] = 0xFF;
+    for(byte_counter=0;byte_counter<9;byte_counter++)
+        RAM[byte_counter] = 0x00; 
+}
+
+bool DS1820::onewire_reset() {
+// This will return false if no devices are present on the data bus
+    bool presence=false;
+    _datapin.output();
+    _datapin.mode(PullUp);
+    _datapin = 0;           // bring low for 500 us
+    wait_us(500);
+    _datapin.input();       // let the data line float high
+    _datapin.mode(PullUp);
+    wait_us(90);            // wait 90us
+    if (_datapin.read()==0) // see if any devices are pulling the data line low
+        presence=true;
+    wait_us(410);
+    return presence;
+}
+
+void DS1820::onewire_bit_out (bool bit_data) {
+    _datapin.output();
+    _datapin = 0;
+    wait_us(5);
+    if (bit_data) {
+        _datapin.input(); // bring data line high
+        _datapin.mode(PullUp);
+        wait_us(55);
+    } else {
+        wait_us(55);            // keep data line low
+        _datapin.input();
+        _datapin.mode(PullUp);
+    }
+}
+
+void DS1820::onewire_byte_out(char data) { // output data character (least sig bit first).
+    int n;
+    for (n=0; n<8; n++) {
+        onewire_bit_out(data & 0x01);
+        data = data >> 1; // now the next bit is in the least sig bit position.
+    }
+}
+
+bool DS1820::onewire_bit_in() {
+    bool answer;
+    _datapin.output();
+    _datapin = 0;
+    wait_us(5);
+    _datapin.input();
+    _datapin.mode(PullUp);
+    wait_us(5);
+    answer = _datapin.read();
+    wait_us(50);
+    return answer;
+}
+
+char DS1820::onewire_byte_in() { // read byte, least sig byte first
+    char answer = 0x00;
+    int i;
+    for (i=0; i<8; i++) {
+        answer = answer >> 1; // shift over to make room for the next bit
+        if (onewire_bit_in())
+            answer = answer | 0x80; // if the data port is high, make this bit a 1
+    }
+    return answer;
+}
+
+bool DS1820::search_ROM() {
+    return search_ROM_routine(0xF0);    // Search ROM command
+}
+
+bool DS1820::search_alarm() {
+    return search_ROM_routine(0xEC);    // Search Alarm command
+}
+
+bool DS1820::search_ROM_routine(char command) {
+    extern bool DS1820_done_flag;
+    extern int DS1820_last_descrepancy;
+    extern char DS1820_search_ROM[8];
+    int descrepancy_marker, ROM_bit_index;
+    bool return_value, Bit_A, Bit_B;
+    char byte_counter, bit_mask;
+
+    return_value=false;
+    if (!DS1820_done_flag) {
+        if (!onewire_reset()) {
+            DS1820_last_descrepancy = 0; // no devices present
+        } else {
+            ROM_bit_index=1;
+            descrepancy_marker=0;
+            onewire_byte_out(command); // Search ROM command or Search Alarm command
+            byte_counter = 0;
+            bit_mask = 0x01;
+            while (ROM_bit_index<=64) {
+                Bit_A = onewire_bit_in();
+                Bit_B = onewire_bit_in();
+                if (Bit_A & Bit_B) {
+                    descrepancy_marker = 0; // data read error, this should never happen
+                    ROM_bit_index = 0xFF;
+                } else {
+                    if (Bit_A | Bit_B) {
+                        // Set ROM bit to Bit_A
+                        if (Bit_A) {
+                            DS1820_search_ROM[byte_counter] = DS1820_search_ROM[byte_counter] | bit_mask; // Set ROM bit to one
+                        } else {
+                            DS1820_search_ROM[byte_counter] = DS1820_search_ROM[byte_counter] & ~bit_mask; // Set ROM bit to zero
+                        }
+                    } else {
+                        // both bits A and B are low, so there are two or more devices present
+                        if ( ROM_bit_index == DS1820_last_descrepancy ) {
+                            DS1820_search_ROM[byte_counter] = DS1820_search_ROM[byte_counter] | bit_mask; // Set ROM bit to one
+                        } else {
+                            if ( ROM_bit_index > DS1820_last_descrepancy ) {
+                                DS1820_search_ROM[byte_counter] = DS1820_search_ROM[byte_counter] & ~bit_mask; // Set ROM bit to zero
+                                descrepancy_marker = ROM_bit_index;
+                            } else {
+                                if (( DS1820_search_ROM[byte_counter] & bit_mask) == 0x00 )
+                                    descrepancy_marker = ROM_bit_index;
+                            }
+                        }
+                    }
+                    onewire_bit_out (DS1820_search_ROM[byte_counter] & bit_mask);
+                    ROM_bit_index++;
+                    if (bit_mask & 0x80) {
+                        byte_counter++;
+                        bit_mask = 0x01;
+                    } else {
+                        bit_mask = bit_mask << 1;
+                    }
+                }
+            }
+            DS1820_last_descrepancy = descrepancy_marker;
+            if (ROM_bit_index != 0xFF) {
+                for(byte_counter=0;byte_counter<8;byte_counter++)
+                    ROM[byte_counter] = DS1820_search_ROM[byte_counter];
+                return_value = true;
+            }
+        }
+        if (DS1820_last_descrepancy == 0)
+            DS1820_done_flag = true;
+    }
+    return return_value;
+}
+
+void DS1820::search_ROM_setup() {
+    extern bool DS1820_done_flag;
+    extern int DS1820_last_descrepancy;
+    extern char DS1820_search_ROM[8];
+    DS1820_done_flag = false;
+    DS1820_last_descrepancy = 0;
+    int i;
+    for (i=0; i<8; i++)
+        DS1820_search_ROM[i]=0x00;
+}
+
+void DS1820::read_ROM() {
+    // NOTE: This command can only be used when there is one DS1820 on the bus. If this command
+    // is used when there is more than one slave present on the bus, a data collision will occur
+    // when all the DS1820s attempt to respond at the same time.
+    int i;
+    onewire_reset();
+    onewire_byte_out(0x33);   // Read ROM id
+    for (i=0; i<8; i++)
+        ROM[i]=onewire_byte_in();
+}
+
+void DS1820::match_ROM() {
+// Used to select a specific device
+    int i;
+    onewire_reset();
+    onewire_byte_out( 0x55);  //Match ROM command
+    for (i=0;i<8;i++)
+        onewire_byte_out(ROM[i]);
+}
+
+void DS1820::skip_ROM() {
+    onewire_reset();
+    onewire_byte_out(0xCC);   // Skip ROM command
+}
+
+bool DS1820::ROM_checksum_error() {
+    char xCRC=0x00;
+    int i;
+    for(i=0;i<7;i++) // Only going to shift the lower 7 bytes
+        xCRC = CRC_byte(xCRC, ROM[i]);
+    // After 7 bytes CRC should equal the 8th byte (ROM CRC)
+    return (xCRC!=ROM[7]); // will return true if there is a CRC checksum error         
+}
+
+bool DS1820::RAM_checksum_error() {
+    char xCRC=0x00;
+    int i;
+    read_RAM();
+    for(i=0;i<8;i++) // Only going to shift the lower 8 bytes
+        xCRC = CRC_byte(xCRC, RAM[i]);
+    // After 8 bytes CRC should equal the 9th byte (RAM CRC)
+    return (xCRC!=RAM[8]); // will return true if there is a CRC checksum error         
+}
+
+char DS1820::CRC_byte (char xCRC, char byte ) {
+    int j;
+    for(j=0;j<8;j++) {
+        if ((byte & 0x01 ) ^ (xCRC & 0x01)) {
+            // DATA ^ LSB CRC = 1
+            xCRC = xCRC>>1;
+            // Set the MSB to 1
+            xCRC = xCRC | 0x80;
+            // Check bit 3
+            if (xCRC & 0x04) {
+                xCRC = xCRC & 0xFB; // Bit 3 is set, so clear it
+            } else {
+                xCRC = xCRC | 0x04; // Bit 3 is clear, so set it
+            }
+            // Check bit 4
+            if (xCRC & 0x08) {
+                xCRC = xCRC & 0xF7; // Bit 4 is set, so clear it
+            } else {
+                xCRC = xCRC | 0x08; // Bit 4 is clear, so set it
+            }
+        } else {
+            // DATA ^ LSB xCRC = 0
+            xCRC = xCRC>>1;
+            // clear MSB
+            xCRC = xCRC & 0x7F;
+            // No need to check bits, with DATA ^ LSB xCRC = 0, they will remain unchanged
+        }
+        byte = byte>>1;
+    }
+return xCRC;
+}
+
+void DS1820::convert_temperature(devices device) {
+    // Convert temperature into scratchpad RAM for all devices at once
+    int delay_time = 750; // Default delay time
+    char resolution;
+    if (device==all_devices)
+        skip_ROM();          // Skip ROM command, will convert for ALL devices
+    else {
+        match_ROM();
+        if (FAMILY_CODE == FAMILY_CODE_DS18B20 ) {
+            resolution = RAM[4] & 0x60;
+            if (resolution == 0x00) // 9 bits
+                delay_time = 94;
+            if (resolution == 0x20) // 10 bits
+                delay_time = 188;
+            if (resolution == 0x40) // 11 bits. Note 12bits uses the 750ms default
+                delay_time = 375;
+        }
+    }
+    onewire_byte_out( 0x44);  // perform temperature conversion
+    if (_parasite_power)
+        _parasitepin = 1;       // Parasite power strong pullup
+    wait_ms(delay_time);
+    if (_parasite_power)
+        _parasitepin = 0;
+}
+
+void DS1820::read_RAM() {
+    // This will copy the DS1820's 9 bytes of RAM data
+    // into the objects RAM array. Functions that use
+    // RAM values will automaticly call this procedure.
+    int i;
+    match_ROM();             // Select this device
+    onewire_byte_out( 0xBE);   //Read Scratchpad command
+    for(i=0;i<9;i++) {
+        RAM[i] = onewire_byte_in();
+    }
+}
+
+bool DS1820::set_configuration_bits(unsigned int resolution) {
+    bool answer = false;
+    resolution = resolution - 9;
+    if (resolution < 4) {
+        resolution = resolution<<5; // align the bits
+        RAM[4] = (RAM[4] & 0x60) | resolution; // mask out old data, insert new
+        write_scratchpad ((RAM[2]<<8) + RAM[3]);
+//        store_scratchpad (DS1820::this_device); // Need to test if this is required
+        answer = true;
+    }
+    return answer;
+}
+
+int DS1820::read_scratchpad() {
+    int answer;
+    read_RAM();
+    answer = (RAM[2]<<8) + RAM[3];
+    return answer;
+}
+
+void DS1820::write_scratchpad(int data) {
+    RAM[3] = data;
+    RAM[2] = data>>8;
+    match_ROM();
+    onewire_byte_out(0x4E);   // Copy scratchpad into DS1820 ram memory
+    onewire_byte_out(RAM[2]); // T(H)
+    onewire_byte_out(RAM[3]); // T(L)
+    if ( FAMILY_CODE == FAMILY_CODE_DS18B20 ) {
+        onewire_byte_out(RAM[4]); // Configuration register
+    }
+}
+
+void DS1820::store_scratchpad(devices device) {
+    if (device==all_devices)
+        skip_ROM();          // Skip ROM command, will store for ALL devices
+    else
+        match_ROM();
+    onewire_byte_out(0x48);   // Write scratchpad into E2 command
+    if (_parasite_power)
+        _parasitepin=1;
+    wait_ms(10);            // Parasite power strong pullup for 10ms
+    if (_parasite_power)
+        _parasitepin=0;
+}
+
+int DS1820::recall_scratchpad(devices device) {
+// This copies the E2 values into the DS1820's memory.
+// If you specify all_devices this will return zero, otherwise
+// it will return the value of the scratchpad memory.
+    int answer=0;
+    if (device==all_devices)
+        skip_ROM();          // Skip ROM command, will recall for ALL devices
+    else
+        match_ROM();
+    onewire_byte_out(0xB8);   // Recall E2 data to scratchpad command
+    wait_ms(10); // not sure I like polling for completion
+                 // it could cause an infinite loop
+    if (device==DS1820::this_device) {
+        read_RAM();
+        answer = read_scratchpad();
+    }
+    return answer;
+}    
+
+float DS1820::temperature(char scale) {
+// The data specs state that count_per_degree should be 0x10 (16), I found my devices
+// to have a count_per_degree of 0x4B (75). With the standard resolution of 1/2 deg C
+// this allowed an expanded resolution of 1/150th of a deg C. I wouldn't rely on this
+// being super acurate, but it does allow for a smooth display in the 1/10ths of a
+// deg C or F scales.
+    float answer, remaining_count, count_per_degree;
+    int reading;
+    read_RAM();
+    reading = (RAM[1] << 8) + RAM[0];
+    if (reading & 0x8000) { // negative degrees C
+        reading = 0-((reading ^ 0xffff) + 1); // 2's comp then convert to signed int
+    }
+    answer = reading +0.0; // convert to floating point
+    if ( FAMILY_CODE == FAMILY_CODE_DS18B20 ) {
+        answer = answer / 8.0;
+    }
+    else {
+        remaining_count = RAM[6];
+        count_per_degree = RAM[7];
+        answer = answer - 0.25 + (count_per_degree - remaining_count) / count_per_degree;
+    }
+    if (scale=='C' or scale=='c')
+        answer = answer / 2.0;
+    else
+        // Convert to deg F
+        answer = answer * 9.0 / 10.0 + 32.0;
+    return answer;
+}
+
+bool DS1820::read_power_supply(devices device) {
+// This will return true if the device (or all devices) are Vcc powered
+// This will return false if the device (or ANY device) is parasite powered
+    if (device==all_devices)
+        skip_ROM();          // Skip ROM command, will poll for any device using parasite power
+    else
+        match_ROM();
+    onewire_byte_out(0xB4);   // Read power supply command
+    return onewire_bit_in();
+}
diff -r 297aba9a5830 -r f760e8507750 DS1820/DS1820.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1820/DS1820.h	Fri Feb 02 10:00:12 2018 +0000
@@ -0,0 +1,263 @@
+/* mbed DS1820 Library, for the Dallas (Maxim) 1-Wire Digital Thermometer
+ * Copyright (c) 2010, Michael Hagberg Michael@RedBoxCode.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_DS1820_H
+#define MBED_DS1820_H
+
+#include "mbed.h"
+
+// ****** THIS GLOBAL VARIABLES MUST BE DEFINED IN main.cpp
+
+// Global variables shared between all DS1820 objects
+//bool DS1820_done_flag;
+//int  DS1820_last_descrepancy;
+//char DS1820_search_ROM[8];
+
+/** DS1820 Dallas 1-Wire Temperature Probe
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ *
+ * #include "TextLCD.h"
+ * #include "DS1820.h"
+ *
+ * TextLCD lcd(p25, p26, p21, p22, p23, p24, TextLCD::LCD16x2); // rs, e, d0-d3, layout
+ *
+ * const int MAX_PROBES = 16;
+ * DS1820* probe[MAX_PROBES];
+ *
+ * int main() {
+ *     int i;
+ *     int devices_found=0;
+ *     // Initialize the probe array to DS1820 objects
+ *     for (i = 0; i < MAX_PROBES; i++)
+ *         probe[i] = new DS1820(p27);
+ *     // Initialize global state variables
+ *     probe[0]->search_ROM_setup();
+ *     // Loop to find all devices on the data line
+ *     while (probe[devices_found]->search_ROM() and devices_found<MAX_PROBES-1)
+ *         devices_found++;
+ *     // If maximum number of probes are found, 
+ *     // bump the counter to include the last array entry
+ *     if (probe[devices_found]->ROM[0] != 0xFF)
+ *         devices_found++;
+ * 
+ *     lcd.cls();
+ *     if (devices_found==0)
+ *         lcd.printf("No devices found");
+ *     else {
+ *         while (true) {
+ *             probe[0]->convert_temperature(DS1820::all_devices);
+ *             lcd.cls();
+ *             for (i=0; i<devices_found; i++) {
+ *                 lcd.printf("%3.1f ",probe[i]->temperature('f'));
+ *             }
+ *         }
+ *     }
+ * }
+ * @endcode
+ */
+ 
+class DS1820 {
+public:
+    enum devices{
+        this_device,     // command applies to only this device
+        all_devices };   // command applies to all devices
+
+    /** Create a probe object connected to the specified pins
+     *
+     * @param data_pin DigitalInOut pin for the data bus
+     * @param power_pin DigitalOut pin to control the power MOSFET
+     */
+    DS1820(PinName data_pin, PinName power_pin); // Constructor with parasite power pin
+
+    /** Create a probe object connected to the specified pin
+     *  this is used when all probes are externally powered
+     *
+     * @param data_pin DigitalInOut pin for the data bus
+     */
+    DS1820(PinName data_pin);
+
+    /** ROM is a copy of the internal DS1820's ROM
+      * It's created during the search_ROM() or search_alarm() commands
+      *
+      * ROM[0] is the Dallas Family Code
+      * ROM[1] thru ROM[6] is the 48-bit unique serial number
+      * ROM[7] is the device xCRC
+      */
+    char ROM[8];
+    #define FAMILY_CODE ROM[0]
+    #define FAMILY_CODE_DS1820 0x10
+    #define FAMILY_CODE_DS18S20 0x10
+    #define FAMILY_CODE_DS18B20 0x28
+    
+    /** RAM is a copy of the internal DS1820's RAM
+      * It's updated during the read_RAM() command
+      * which is automaticaly called from any function
+      * using the RAM values.
+      */
+    char RAM[9];
+    
+    /* This function copies the DS1820's RAM into the object's
+     * RAM[].
+     */
+    void read_RAM();
+
+    /** This routine initializes the global variables used in
+      * the search_ROM() and search_alarm() funtions. It should
+      * be called once before looping to find devices.
+      */
+    void search_ROM_setup();
+
+    /** This routine will search for an unidentified device
+      * on the bus. It uses the variables in search_ROM_setup
+      * to remember the pervious ROM address found.
+      * It will return FALSE if there were no new devices
+      * discovered on the bus.
+      */
+    bool search_ROM();
+
+    /** This routine will search for an unidentified device
+      * which has the temperature alarm bit set. It uses the 
+      * variables in search_ROM_setup to remember the pervious 
+      * ROM address found. It will return FALSE if there were 
+      * no new devices with alarms discovered on the bus.
+      */
+    bool search_alarm();
+
+    /** This routine will read the ROM (Family code, serial number
+      * and Checksum) from a dedicated device on the bus.
+      *
+      * NOTE: This command can only be used when there is only one 
+      *       DS1820 on the bus. If this command is used when there 
+      *       is more than one slave present on the bus, a data 
+      *       collision will occur when all the DS1820s attempt to 
+      *       respond at the same time.
+      */
+    void read_ROM();
+
+    /** This routine will initiate the temperature conversion within
+      * a DS1820. There is a built in 750ms delay to allow the 
+      * conversion to complete.
+      *
+      * To update all probes on the bus, use a statement such as this:
+      * probe[0]->convert_temperature(DS1820::all_devices);
+      *
+      * @param allows the fnction to apply to a specific device or
+      * to all devices on the 1-Wire bus.
+      */
+    void convert_temperature(devices device=this_device);
+
+    /** This function will return the probe temperature. This function
+      * uses the count remainding values to interpolate the temperature
+      * to about 1/150th of a degree. Whereas the probe is not spec to
+      * that precision. It does seem to give a smooth reading to the
+      * tenth of a degree.
+      *
+      * @param scale, may be either 'c' or 'f'
+      * @returns temperature for that scale
+      */
+    float temperature(char scale='c');
+    
+    /** This function calculates the ROM checksum and compares it to the
+      * xCRC value stored in ROM[7].
+      *
+      * @returns true if the checksum matches, otherwise false.
+      */
+    bool ROM_checksum_error();
+
+    /** This function calculates the RAM checksum and compares it to the
+      * xCRC value stored in RAM[8].
+      *
+      * @returns true if the checksum matches, otherwise false.
+      */
+    bool RAM_checksum_error();
+
+    /** This function returns the values stored in the temperature
+      * alarm registers. 
+      *
+      * @returns a 16 bit integer of TH (upper byte) and TL (lower byte).
+      */
+    bool set_configuration_bits(unsigned int resolution);
+    
+    /** This function sets the temperature resolution for the DS18B20
+      * in the configuration register.
+      *
+      * @param a number between 9 and 12 to specify the resolution
+      * @returns true if successful
+      */
+    int read_scratchpad();
+    
+    /** This function will store the passed data into the DS1820's RAM.
+      * Note: It does NOT save the data to the EEPROM for retention
+      * during cycling the power off and on.
+      *
+      * @param a 16 bit integer of TH (upper byte) and TL (lower byte).
+      */
+    void write_scratchpad(int data);
+    
+    /** This function will transfer the TH and TL registers from the
+      * DS1820's RAM into the EEPROM.
+      * Note: There is a built in 10ms delay to allow for the
+      * completion of the EEPROM write cycle.
+      *
+      * @param allows the fnction to apply to a specific device or
+      * to all devices on the 1-Wire bus.
+      */
+    void store_scratchpad(devices device=this_device);
+
+    /** This function will copy the stored values from the EEPROM
+      * into the DS1820's RAM locations for TH and TL.
+      *
+      * @param allows the function to apply to a specific device or
+      * to all devices on the 1-Wire bus.
+      */
+    int recall_scratchpad(devices device=this_device);
+
+    /** This function will return the type of power supply for
+      * a specific device. It can also be used to query all devices
+      * looking for any device that is parasite powered.
+      *
+      * @returns true if the device (or all devices) are Vcc powered,
+      * returns false if the device (or ANY device) is parasite powered.
+      */
+    bool read_power_supply(devices device=this_device);
+private:
+    bool _parasite_power;
+    char CRC_byte (char xCRC, char byte );
+    bool onewire_reset();
+    void match_ROM();
+    void skip_ROM();
+    bool search_ROM_routine(char command);
+    void onewire_bit_out (bool bit_data);
+    void onewire_byte_out(char data);
+    bool onewire_bit_in();
+    char onewire_byte_in();
+
+protected:
+    DigitalInOut _datapin;
+    DigitalOut _parasitepin;
+};
+
+
+#endif
diff -r 297aba9a5830 -r f760e8507750 Sigfox.lib
--- a/Sigfox.lib	Wed Jan 17 14:34:05 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/dahmani_belkacem/code/Sigfox/#43a4b8ba4635
diff -r 297aba9a5830 -r f760e8507750 main.cpp
--- a/main.cpp	Wed Jan 17 14:34:05 2018 +0000
+++ b/main.cpp	Fri Feb 02 10:00:12 2018 +0000
@@ -1,171 +1,173 @@
 #include "mbed.h"
-#include "SerialGPS.h"
 #include "DHT22.h"
-#include "Sigfox.h"
-#include "BufferedSerial.h"
-//#include "ATParser.h"
+#include "string.h"
+#include "DS1820.h"
 
  
-Serial pc(USBTX, USBRX); // tx, rx
-SerialGPS gps(PC_10,PC_11);  // tx, rx
-DHT22 dht22(D4);//pin pour la lecture du dht22 grove
-DHT22 dht22Bis(D5);//pin pour la lecture du dht22 
+Serial pc(USBTX,USBRX); // tx, rx
+Serial sigfox(PA_9,PA_10); // tx, rx
+DHT22 dht22(D3);//pin pour la lecture du dht22 grove
+DHT22 dht22Bis(D6);//pin pour la lecture du dht22 
 AnalogIn IRSensor(A1);//Pin de lecture du capteur IR
-
-BufferedSerial serial = BufferedSerial(PC_10,PC_11);
-//ATParser at = ATParser(serial, "\r\n");
-Sigfox sig(*);
-
-//Sigfox(at(&at));
+DigitalOut led0(LED1);
+DigitalOut led1(LED2);
+double longi;
+double lat;
+const int MAX_PROBES = 1;
+DS1820 probe[1] = {A4};
 
 
-//programme du gps
-
-/**
- * A callback function for logging data.
- */
-void cbfunc_log(char *s) {
-
-}
-
-/**
- * A callback function for GGA.
- *
- * GGA - Global Positioning System Fixed Data.
- */
-void cbfunc_gga(SerialGPS::gps_gga_t *p) {
-
-     pc.printf("%02d:%02d:%02d(P%d,S%d)\r\n", p->hour, p->min, p->sec, p->position_fix, p->satellites_used);
-
-       // pc.printf("latitude  %c=%10.4f\r\n", p->ns, p->latitude);
-
-       // pc.printf("longitude %c=%10.4f\r\n", p->ew, p->longitude);
-        double a = p->latitude;
-        double b = p->longitude;
-        pc.printf("latitude %10.4f\r\n", a);
-        pc.printf("longitude %10.4f\r\n", b);
-}
-
-/**
- * A callback function for GSA.
- *
- * GSA - GNSS DOP and Active Satellites.
- */
-void cbfunc_gsa(SerialGPS::gps_gsa_t *p) {
-
-  pc.printf("SEL:%c FIX:%d\r\n", p->selmode, p->fix);
-  
-}
-
-/**
- * A callback function for GSV.
- *
- * GSV - GNSS Satellites in View.
- */
-void cbfunc_gsv(SerialGPS::gps_gsv_t *p) {
- 
-      pc.printf("Satellites:%2d\r\n", p->satcnt);
-
-}
-
-/**
- * A callback function for RMC.
- *
- * RMC - Recommended Minimum Specific GNSS Data.
- */
-void cbfunc_rmc(SerialGPS::gps_rmc_t *p) {
-
-     pc.printf("%02d:%02d:%02d(%c)\r\n", p->hour, p->min, p->sec, p->status);
-
-}
-
-/**
- * Entry point.
- */
-
-//fin du prgramme de lecture GPS
 
 //Fonction lecture des donneé sigfox
 
  
 int main() {
-    //programme main du gps
-        //programme main de lecture DHT22
-    
-    int hum;
-    int temp;
-    int hum1;
-    int temp1;
-    
+  
+   int humExt;  // humidité intérieur dst22
+   int tempExt; // température extérieur dst22
+   int humInt;  // humidité intérieur dst22
+   int tempInt; // température intérieur dst22
+   int i;
+   int devices_found=0;
+   int tempDs; //tempérarure de la sonde Ds18B20;
+   
     pc.baud(9600);
- 
+    sigfox.baud(9600);
     
     pc.printf("TEST\r\n");
     wait(0.5);
-    pc.printf("TEST1\r\n");
-    
-    SerialGPS::gps_callback_t cb;
-    cb.cbfunc_log = cbfunc_log;
-    pc.printf("TEST2\r\n");
+
+    //partie declarative DS18B20
+    pc.printf("Started\r\n");
+    pc.printf("search_ROM_setup\r\n");
+    probe[0].search_ROM_setup();
+    pc.printf("search_ROM\r\n");
+ 
+     while (probe[devices_found].search_ROM() and devices_found<MAX_PROBES-1)
+          devices_found++;
     
-    cb.cbfunc_gsa = cbfunc_gsa;
-    cb.cbfunc_gsv = cbfunc_gsv;
-    cb.cbfunc_rmc = cbfunc_rmc;
-    gps.attach(&cb);
-    pc.printf("TEST3\r\n");
-
+    // If maximum number of probes are found,
+    // bump the counter to include the last array entry
+    if (probe[devices_found].ROM[0] != 0xFF)
+        devices_found++;
+    pc.printf("devices found:%d\r\n",devices_found);
+    
+        //Fin de la partie declarative DS18B20   
+        
     while(1) {
-        
+     char donnee[] = "AT$SF=";
      wait(1);
-     gps.processing();
      pc.printf("TEST4\r\n");
-     //lecture du DHT22 grove
-             
-       dht22.sample() ;
-        hum=dht22.getHumidity()/10.0;
-        temp=dht22.getTemperature()/10.0;
-        printf("temperature: %d, humidity: %d\n\r",temp,hum);
+     
+   //  lecture du DHT22 grove
+            
+        dht22.sample() ;
+        humExt=dht22.getHumidity()/10.0;
+        tempExt=dht22.getTemperature()/10.0;
+        pc.printf("temperature: %d humidity: %d\n\r",tempExt,humExt);
         
-        //lecture du DHT22 simple
-        
-        dht22Bis.sample() ;
-        hum1=dht22Bis.getHumidity()/10.0;
-        temp1=dht22Bis.getTemperature()/10.0;
-        printf("temperature1: %3d, humidity1: %3d\n\r",temp1,hum1);
+        //lecture du DHT22 simple Intérieure 
+      
+        dht22Bis.sample(); 
+        humInt=dht22Bis.getHumidity()/10.0;
+        tempInt=dht22Bis.getTemperature()/10.0;
+        pc.printf("temperature1: %d humidity1: %d\n\r",tempInt,humInt);
       
         //mesure de la distance 
-        
-        //wait(2);
-       //3.1V at 4cm to 0.3V at 30cm. 
+      
+             //3.1V at 4cm to 0.3V at 30cm. 
        float a = IRSensor;// 1=4cm 0=30cm
-       pc.printf("IR sensor reads %2.2f\n ", a);
-       a=1-a;// now 0=4cm and 1=30cm 
-       float b= 40+a * 260; //(a26+4);
-       pc.printf("\rDistance is %2.2f mm \n ", b); // print and convert to distance by taking x=0->1 and 26x+4
-      float x = 200 - b;
-      float f = 2.913*x;
-      int m= 1000*(f/(9.8));
-      pc.printf("\la masse de la ruche est egale a %2.2f g \n ",m); 
+       //pc.printf("IR sensor reads %2.2f\n ", a);
+       float v=2.8*a;
+      //  pc.printf("\r ANALOGIN %2.2f v \n ", v);
+       float l= 10*((12/v)-0.42);
      
-      sig->send(""+m);
+       pc.printf("\rDistance is %2.2f mm \n ", l); // print and convert to distance by taking x=0->1 and 26*x+4
+       float x=193-l;//218
+       float f= 4*(2.913*x);//2.5
+       int m = (f/(9.8));
+       pc.printf("\la masse de la ruche est égale à %d Kg \n ",m); 
+       
+       //mesure de la température avec DS18B20
+
+        probe[0].convert_temperature(DS1820::all_devices);
+        for (i=0; i<devices_found; i++) {
+            tempDs = probe[i].temperature('c');
+            pc.printf("Device[%d]: %d \r\n",i,tempDs);
+        }
+       
+       //fin de mesure de temperature avec DS18B20
+    
+      
+        pc.printf("TEST5\r\n");
+
+    
+        
+        
+        if(humExt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt);
+         pc.printf("\n");
+         
+       if(humInt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt);
+         pc.printf("\n");
+         
+        if(tempDs<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs);
+         pc.printf("\n");
+         
+        if(m<=16){
+        strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs,m); 
+         
+         pc.printf("\n");     
+          
+        if(tempExt<=16){
+           strcat(donnee,"0%x");
+        }else {strcat(donnee,"%2x");}
+        pc.printf(donnee,humExt,humInt,tempDs,m,tempExt);
+        pc.printf("\n");
+        
+        if(tempInt<=16){
+           strcat(donnee,"0%x ");
+        }else {strcat(donnee,"%2x ");}
+         pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         pc.printf("\n");
+         sigfox.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         pc.printf("\n");
+         pc.printf(donnee,humExt,humInt,tempDs,m,tempExt,tempInt);
+         
+         // pc.printf(donnee);
+          pc.printf("TEST6\r\n");
+          led0 = 1;
+          led1 = 1;
+          wait (10);
+          //wait(0.1); // wait 100 ms
+        
+                 //  LEDs OFF
+                   led0 = 0;
+                   led1 = 0;
       
       
-      wait(1);
+                // wait(660);
+        
+           
     
 
     }
-       //programme main de lecture DHT22
+     
     
 
     
 
-    
-/*    while (1) {
-        
-       
-    }
-  */  
-    //Fin du programme de lecture DHT22
+
     
  
 }