Commit b1fde404 authored by Antoine Rivera's avatar Antoine Rivera
Browse files

Mise à jour consommation

parent 81fa5bcc
# Serres connectées
## Infos LoRa Server
Application
### Accès à l'application
https://lora.campusiot.imag.fr/#/organizations/18/applications/89
#### EUI des boîtiers
Device EUI
STM32_1 4004477f65c063a2
STM32_2 9876543210987654
STM32_3 a66275a933989b71
* Boîtier n°1 : `4004477f65c063a2`
* Boîtier n°2 : `9876543210987654`
* Boîtier n°3 : `a66275a933989b71`
## Consignes d'utilisation de l'IDE
Pour développer le code des boîtiers, nous utilisons le framework `mbed` grâce à l’environnement `PlatformIO`. (On n'utilise pas le site mbed mais uniquement son framework)
Pour simplifier son utilisation, nous l'utiliserons via son plug-in officiel dans l'IDE `Visual Studio Code`
### Installation
Premièrement, si vous ne la'avez pas déjà, il vous faudra installer `Visual Studio Code` à [cette adresse](https://code.visualstudio.com/download). (Attention, `Visual Studio Code` =/= `Visual Studio`)
Une fois `VSCode` installé, rendez-vous dans l'onglet `Extensions` pour installer `PlatformIO`.
![alt text](images/ExtensionsPanel.png "Title Text")
![alt text](images/ExtensionsPIO.png "Title Text")
Une fois l'extension installée, il vous suffit d'ouvrir le dossier du code en faisant `File -> Open folder`
Utilisez ensuite les boutons du bas pour `compiler` et `uploader` le programme sur la carte STM.
![alt text](images/PIOButtons.png "Title Text")
En cas de changement de carte ou autre, tous les paramètres du projet se trouvent dans le fichier `platformio.ini`. ([Documentation](https://docs.platformio.org/en/latest/projectconf/))
Si vous avez besoin d'aide sur autre-chose ou si vous avez des question quelconques, n'hésitez pas à me contacter (Farès Chati sur Facebook).
\ No newline at end of file
STM32_Test ad609c8db596f89e
\ No newline at end of file
#include "Lorawan.h"
#include "lorawan.h"
#include "mbed.h"
#include "standby.h"
#define CARTE_NO 3
extern Serial pc;
#define CARTE_NO 2
#if CARTE_NO == 1
static uint8_t DevEui[] = { 0x40, 0x04, 0x47, 0x7f, 0x65, 0xc0, 0x63, 0xa2 };
......@@ -16,10 +20,11 @@ static uint8_t AppKey[] = { 0x91, 0x3c, 0xa4, 0x34, 0xeb, 0xa2, 0xbe, 0x5f, 0x8d
static uint8_t AppEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static uint8_t AppPort = LORAWAN_APP_PORT;
static uint8_t AppDataSize = LORAWAN_APP_DATA_SIZE;
static uint8_t AppDataSize = 0; //LORAWAN_APP_DATA_SIZE
static uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE];
static uint8_t IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
static uint8_t JoinTrials = 0; //BS_TO_DO
static enum eDeviceState
{
......@@ -74,38 +79,58 @@ volatile bool DownlinkStatusUpdated = false;
static void PrepareTxFrame (uint8_t port)
{
int temp1, humi1, temp2, humi2, temp3, humi3;
uint8_t bat = 0;
AppData[0] = 1;
AppData[AppDataSize++] = 1;
if (IsTxConfirmed == true)
{
sensors.getSensorsIntValue (&temp1, &humi1, &temp2, &humi2, &temp3, &humi3);
bat = BoardGetBatteryLevel();
// Temperature roof
AppData[1] = (temp1 >> 8);
AppData[2] = (uint8_t) temp1;
pc.printf("Temperature 1 : %d\r\n", temp1);
AppData[AppDataSize++] = 103;
AppData[AppDataSize++] = (temp1 >> 8) & 0xFF;
AppData[AppDataSize++] = (uint8_t) (temp1 & 0xFF);
// Humidity roof
AppData[3] = 2;
AppData[4] = (uint8_t) humi1;
pc.printf("Humidity 1 : %d\r\n", humi1);
AppData[AppDataSize++] = 1;
AppData[AppDataSize++] = 104;
AppData[AppDataSize++] = (uint8_t) (humi1 & 0xFF);
// Temperature ground
AppData[5] = 12;
AppData[6] = (temp2 >> 8);
AppData[7] = (uint8_t) temp2;
pc.printf("Temperature 2 : %d\r\n", temp2);
AppData[AppDataSize++] = 2;
AppData[AppDataSize++] = 103;
AppData[AppDataSize++] = (temp2 >> 8) & 0xFF;
AppData[AppDataSize++] = (uint8_t) (temp2 & 0xFF);
// Humidity ground
AppData[8] = 26;
AppData[9] = (uint8_t) humi2;
pc.printf("Humidity 2 : %d\r\n", humi2);
AppData[AppDataSize++] = 2;
AppData[AppDataSize++] = 104;
AppData[AppDataSize++] = (uint8_t) (humi2 & 0xFF);
// Temperature uderground
AppData[10] = 25;
AppData[11] = (temp3 >> 8);
AppData[12] = (uint8_t) temp3;
pc.printf("Temperature 3 : %d\r\n", temp3);
AppData[AppDataSize++] = 3;
AppData[AppDataSize++] = 103;
AppData[AppDataSize++] = (temp3 >> 8) & 0xFF;
AppData[AppDataSize++] = (uint8_t) (temp3 & 0xFF);
// Humidity underground
AppData[13] = 27;
AppData[14] = (uint8_t) humi3;
pc.printf("Humidity 3 : %d\r\n", humi3);
AppData[AppDataSize++] = 3;
AppData[AppDataSize++] = 104;
AppData[AppDataSize++] = (uint8_t) (humi3 & 0xFF);
// Battery level
pc.printf("Battery : %d\r\n", bat);
AppData[AppDataSize++] = 1;
AppData[AppDataSize++] = 0;
AppData[AppDataSize++] = bat;
}
} // PrepareTxFrame
......@@ -155,6 +180,7 @@ static bool SendFrame (void)
if (LoRaMacMcpsRequest (&mcpsReq) == LORAMAC_STATUS_OK)
{
pc.printf("Request = STATUS OK\r\n");
return false;
}
return true;
......@@ -393,6 +419,7 @@ static void MlmeConfirm (MlmeConfirm_t * mlmeConfirm)
switch (mlmeConfirm->MlmeRequest)
{
case MLME_JOIN:
pc.printf("MLME_JOIN %d\r\n",mlmeConfirm->Status);
if (mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK)
{
// Status is OK, node has joined the network
......@@ -407,6 +434,7 @@ static void MlmeConfirm (MlmeConfirm_t * mlmeConfirm)
break;
case MLME_LINK_CHECK:
pc.printf("MLME_LINK_CHECK %d\r\n",mlmeConfirm->Status);
if (mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK)
{
// Check DemodMargin
......@@ -421,6 +449,7 @@ static void MlmeConfirm (MlmeConfirm_t * mlmeConfirm)
break;
default:
pc.printf("MLME = %d,%d\r\n",mlmeConfirm->MlmeRequest, mlmeConfirm->Status);
break;
}
UplinkStatusUpdated = true;
......@@ -428,6 +457,9 @@ static void MlmeConfirm (MlmeConfirm_t * mlmeConfirm)
void initLoraWan ()
{
_SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);
GPIOA->MODER = (GPIOA->MODER & ~0xC) | 0x4; //Utilisation de PIA1 pour l'alimentation des capteurs -> alim commandée
GPIOA->ODR |= 0x2;
sensors.initSensors();
BoardInit();
......@@ -439,7 +471,7 @@ LoRaMacPrimitives_t LoRaMacPrimitives_;
LoRaMacCallback_t LoRaMacCallbacks_;
MibRequestConfirm_t mibReq_;
void loraWanAction ()
void loraWanAction (uint8_t MaxTrials)
{
while (DeviceState != DEVICE_STATE_SLEEP)
{
......@@ -508,7 +540,14 @@ void loraWanAction ()
mlmeReq.Req.Join.DevEui = DevEui;
mlmeReq.Req.Join.AppEui = AppEui;
mlmeReq.Req.Join.AppKey = AppKey;
mlmeReq.Req.Join.NbTrials = 100;
#define HEX8(X) X[0],X[1], X[2],X[3], X[4],X[5], X[6],X[7]
#define HEX16(X) X[0],X[1], X[2],X[3], X[4],X[5], X[6],X[7],X[8],X[9], X[10],X[11], X[12],X[13], X[14],X[15]
mlmeReq.Req.Join.NbTrials = 100;
pc.printf( "DevEui= %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n\r", HEX8(DevEui));
pc.printf( "AppEui= %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n\r", HEX8(AppEui));
pc.printf( "AppKey= %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n\r", HEX16(AppKey));
pc.printf( "Join Trials = %d\n\r", mlmeReq.Req.Join.NbTrials);
LoRaMacMlmeRequest (&mlmeReq);
......@@ -521,6 +560,7 @@ void loraWanAction ()
MibRequestConfirm_t mibReq;
LoRaMacStatus_t status;
thread_sleep_for(10000 /* in ms */);
mibReq.Type = MIB_NETWORK_JOINED;
status = LoRaMacMibGetRequestConfirm (&mibReq);
......@@ -534,6 +574,11 @@ void loraWanAction ()
DeviceState = DEVICE_STATE_SLEEP;
}
//BS_TO_DO else go to sleep
else if(JoinTrials++ > MaxTrials)
{
DeviceState = DEVICE_STATE_SLEEP;
}
}
else
{
......
......@@ -26,7 +26,7 @@
#define LC10 { 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 }
#define LORAWAN_APP_PORT 15
#define LORAWAN_APP_DATA_SIZE 15
#define LORAWAN_APP_DATA_SIZE 24
#define LORAWAN_APP_DATA_MAX_SIZE 64
static void PrepareTxFrame (uint8_t port);
......@@ -35,6 +35,6 @@ static void McpsConfirm (McpsConfirm_t * mcpsConfirm);
static void McpsIndication (McpsIndication_t * mcpsIndication);
static void MlmeConfirm (MlmeConfirm_t * mlmeConfirm);
void initLoraWan ();
void loraWanAction ();
void loraWanAction (uint8_t MaxTrials/* BS_TO_DO */);
#endif // ifndef LORAWAN_H
\ No newline at end of file
......@@ -24,7 +24,7 @@ float SHT31::readHumidity (void)
void SHT31::reset ()
{
writeCommand (SHT31_SOFTRESET);
wait_ns (10000);
wait_ms (10);
}
uint16_t SHT31::readStatus (uint8_t tries)
......
......@@ -64,7 +64,7 @@ namespace SHTx {
this->input();
for (uint8_t i = 0; i < 500 && !ack; i++) {
wait_ns(1000);
wait_ms(1);
ack = !this->sda_pin;
}
......
......@@ -29,7 +29,7 @@
namespace SHTx {
SHT15::SHT15(PinName sda, PinName scl): i2c(sda, scl) {
this->ready = true;
wait_ns(11000);
wait_ms(11);
}
float
......@@ -106,7 +106,7 @@ namespace SHTx {
this->status_register = 0;
this->humidity = 0;
this->temperature = 0;
wait_ns(11000);
wait_ms(11);
return true;
}
......
......@@ -26,4 +26,4 @@ void Sensors::getSensorsIntValue (int * temp1, int * humi1, int * temp2, int * h
*humi3 = (int) (sensor3.getHumidity()); // Humidity - Sol
}
Sensors sensors;
\ No newline at end of file
Sensors sensors = Sensors();
\ No newline at end of file
......@@ -40,7 +40,7 @@ int config_RTC(const uint16_t time)
RTC->WUTR = time-1; // Wake up value reload counter [s]
RTC->PRER = 0x7F00FF; // ck_spre = 1Hz PREDIV_A = 0x7F(127) PREDIV_S = 0xFF(255) using LSE (32768Hz). ck = (32768)/(PREDIV_A * PREDIV_S)
// OSEL (output selection) = 0x3 -> RTC_ALARM output = Wake up timer
_SET_BIT(RTC->CR, RTC_CR_OSEL);
// BS_TO_DO Overcurrent 700uA _SET_BIT(RTC->CR, RTC_CR_OSEL);
// WUCKSEL = 0x4 -> RTC Timer [1s - 18h]
_SET_BIT(RTC->CR, RTC_CR_WUCKSEL_2);
// Enable wake up counter/interrupt
......@@ -94,10 +94,10 @@ void standby_verification(void)
// clear PWR Standby flag
_SET_BIT(PWR->CR, PWR_CR_CSBF);
printf("\nLa carte se reveille du mode standby\n");
printf("La carte se reveille du mode standby\r\n");
}
else {
printf("\nLa carte se reveille du power cycle\n");
printf("La carte se reveille du power cycle\r\n");
}
}
......
......@@ -142,7 +142,7 @@ uint8_t SX1272MB2xAS::DetectBoardType( void )
boardConnected = MDOT_F411RE;
#else
this->AntSwitch.input( );
wait_ns( 1000 );
wait_ms( 1 );
if( this->AntSwitch == 1 )
{
boardConnected = SX1272MB1DCS;
......@@ -152,7 +152,7 @@ uint8_t SX1272MB2xAS::DetectBoardType( void )
boardConnected = SX1272MB2XAS;
}
this->AntSwitch.output( );
wait_ns( 1000 );
wait_ms( 1 );
#endif
}
return ( boardConnected );
......@@ -186,7 +186,7 @@ void SX1272MB2xAS::SpiInit( void )
#else
#warning "Check the board's SPI frequency"
#endif
wait_ns(100000);
wait(0.1);
}
void SX1272MB2xAS::IoIrqInit( DioIrqHandler *irqHandlers )
......@@ -405,9 +405,9 @@ void SX1272MB2xAS::Reset( void )
{
reset.output( );
reset = 0;
wait_ns( 1000 );
wait_ms( 1 );
reset.input( );
wait_ns( 6000 );
wait_ms( 6 );
}
void SX1272MB2xAS::Write( uint8_t addr, uint8_t data )
......
......@@ -51,7 +51,7 @@ SX1272::SX1272( RadioEvents_t *events,
dio0( dio0 ), dio1( dio1 ), dio2( dio2 ), dio3( dio3 ), dio4( dio4 ), dio5( dio5 ),
isRadioActive( false )
{
wait_ns( 10000 );
wait_ms( 10 );
this->rxtxBuffer = new uint8_t[RX_BUFFER_SIZE];
this->RadioEvents = events;
......@@ -103,7 +103,7 @@ bool SX1272::IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThre
SetOpMode( RF_OPMODE_RECEIVER );
wait_ns( 1000 );
wait_ms( 1 );
rssi = GetRssi( modem );
......@@ -142,7 +142,7 @@ uint32_t SX1272::Random( void )
for( i = 0; i < 32; i++ )
{
wait_ns( 1000 );
wait_ms( 1 );
// Unfiltered RSSI value reading. Only takes the LSB value
rnd |= ( ( uint32_t )Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
}
......@@ -560,7 +560,7 @@ void SX1272::Send( uint8_t *buffer, uint8_t size )
if( ( Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
{
Standby( );
wait_ns( 1000 );
wait_ms( 1 );
}
// Write payload buffer
WriteFifo( buffer, size );
......
......@@ -12,5 +12,6 @@
platform = ststm32
board = nucleo_l073rz
framework = mbed
platform_packages = framework-mbed @ 5.51401.191023
build_flags =
-I"lib/"
\ No newline at end of file
#include "Lorawan.h"
#include "lorawan.h"
#include "standby.h"
#include "mbed.h"
int main (void)
Serial pc(USBTX, USBRX);
void Error_Handler(char* filename, unsigned int line)
{
initLoraWan();
loraWanAction();
pc.printf("Error in %s@%d !!\r\n", filename, line);
while (1);
}
standby_mode (5 * 60);
}
\ No newline at end of file
int main(void)
{
pc.baud(115200);
pc.printf("Booting...\r\n");
standby_verification();
#if 1
initLoraWan();
pc.printf("LoraWan init done\r\n");
loraWanAction(2);
Radio.Sleep( );
#endif
pc.printf("Standby...\r\n");
config_GPIO();
// Reset All GPIO port
RCC->IOPRSTR = 0x9F;
RCC->IOPRSTR = 0x0;
standby_mode(5 * 60);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment