4G 08a: Send to Meshlium (HTTP)

This example shows how to use HTTP requests to send Waspmote frames from Waspmote to Meshlium. Therefore, the Meshlium will be able to parse the sensor data and inset it into the database

Required Materials

1 x Waspmote 1 x Battery 1 x 4G module 1 x 4G antenna 1 x SIM card

Notes

- The battery has to be connected. - This example can be executed in Waspmote v15

Code

/*
    --------------- 4G_08 - Send frames to Meshlium  ---------------

    Explanation: This example shows how to use HTTP requests to send
    Waspmote frames from Waspmote to Meshlium. Therefore, the Meshlium
    will be able to parse the sensor data and inset it into the database

    NOTE: This example is valid for Meshlium Manager System versions
    prior to v4.0.9 which only supports HTTPS.

    Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
    http://www.libelium.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program.  If not, see .

    Version:           3.0
    Design:            David Gascón
    Implementation:    Alejandro Gállego
*/

#include  <Wasp4G.h>
#include <WaspFrame.h>

// APN settings
///////////////////////////////////////
char apn[] = "";
char login[] = "";
char password[] = "";
///////////////////////////////////////

// SERVER settings
///////////////////////////////////////
char host[] = "pruebas.libelium.com";
uint16_t port = 80;
///////////////////////////////////////

// define the Waspmote ID
char moteID[] = "node_01";
int error;



void setup()
{
  USB.ON();
  USB.println(F("Start program"));

  // set the Waspmote ID
  frame.setID(moteID);


  //////////////////////////////////////////////////
  // 1. sets operator parameters
  //////////////////////////////////////////////////
  _4G.set_APN(apn, login, password);

  //////////////////////////////////////////////////
  // 2. Show APN settings via USB port
  //////////////////////////////////////////////////
  _4G.show_APN();
}



void loop()
{
  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////
  error = _4G.ON();

  if (error == 0)
  {
    USB.println(F("1. 4G module ready..."));


    ////////////////////////////////////////////////
    // 2. Create new frame
    ////////////////////////////////////////////////

    RTC.ON();
    RTC.getTime();

    // Create new frame (ASCII)
    frame.createFrame(ASCII);
    // set frame fields (Time from RTC)
    frame.addSensor(SENSOR_TIME, RTC.hour, RTC.minute, RTC.second);


    ////////////////////////////////////////////////
    // 3. Send to Meshlium
    ////////////////////////////////////////////////
    USB.print(F("Sending the frame..."));
    error = _4G.sendFrameToMeshlium( host, port, frame.buffer, frame.length);

    // check the answer
    if ( error == 0)
    {
      USB.print(F("Done. HTTP code: "));
      USB.println(_4G._httpCode);
      USB.print("Server response: ");
      USB.println(_4G._buffer, _4G._length);
    }
    else
    {
      USB.print(F("Failed. Error code: "));
      USB.println(error, DEC);
    }
  }
  else
  {
    // Problem with the communication with the 4G module
    USB.println(F("4G module not started"));
    USB.print(F("Error code: "));
    USB.println(error, DEC);
  }


  ////////////////////////////////////////////////
  // 4. Powers off the 4G module
  ////////////////////////////////////////////////
  USB.println(F("4. Switch OFF 4G module"));
  _4G.OFF();


  ////////////////////////////////////////////////
  // 5. Sleep
  ////////////////////////////////////////////////
  USB.println(F("5. Enter deep sleep..."));
  PWR.deepSleep("00:00:00:10", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

  USB.ON();
  USB.println(F("6. Wake up!!\n\n"));

}

Output

H#
Start program
*****************************
APN:
LOGIN:
PASSWORD:
*****************************
1. 4G module ready...
Sending the frame...Done. HTTP code: 200
Server response: method::POST;
POST;frame::3C3D3E86012336343444353330453639354234413238236E6F64655F303123302354494D453A302D31332D343823;
TIME:0-13-48 ,
4. Switch OFF 4G module
5. Enter deep sleep...
6. Wake up!!
1. 4G module ready...
Sending the frame...Done. HTTP code: 200
Server response: method::POST;
POST;frame::3C3D3E86012336343444353330453639354234413238236E6F64655F303123312354494D453A302D31342D313323;
TIME:0-14-13 ,
4. Switch OFF 4G module
5. Enter deep sleep...ó6. Wake up!!

Last updated