Open Storm
Functions
data.h File Reference

Declares the sensor subroutine, metadata updater, trigger updater, and parameter updater. More...

#include <device.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "decagon.h"
#include "ultrasonic.h"
#include "optical_rain.h"
#include "atlas_wq_sensor.h"
#include "autosampler.h"
#include "valve.h"
#include "misc.h"
#include "modem.h"
#include "strlib.h"
#include "commit.h"
Include dependency graph for data.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int take_readings (char *labels[], float readings[], uint8 *array_ix, uint8 take_average, uint8 max_size)
 Takes sensor readings and stores results into an array of labels and an array of readings. More...
 
uint8 execute_triggers (char *labels[], float readings[], uint8 *array_ix, uint8 max_size)
 Executes triggers and stores results into an array of labels and an array of readings. More...
 
uint8 zip_meta (char *labels[], float readings[], uint8 *array_ix, uint8 max_size)
 Inserts current value of meta_trigger into readings array. More...
 
uint8 zip_modem (char *labels[], float readings[], uint8 *array_ix, uint8 max_size)
 Inserts current values of connection_attempt_counter rssi and fer into readings array. More...
 
uint8 run_meta_subroutine (char *meid, char *send_str, char *response_str, uint8 get_device_meid)
 Runs update_meta and stores the results in an array of readings and labels. More...
 
int update_meta (char *meid, char *send_str, char *response_str)
 Update values of node_id, node_user, node_pass, node_db on device based on current values stored on server. More...
 
int update_triggers (char *body, char *send_str, char *response_str)
 Update values of triggers, such as valve_trigger, autosampler_trigger and gps_trigger based on current values stored on server. More...
 
void update_params (char *body, char *send_str, char *response_str)
 Update values of onboard parameters, such as sleeptimer and flags such as ultrasonic_flag or valve_flag. More...
 
void construct_route (char *route, char *base, char *user, char *pass, char *database)
 Constructs the route (URL) following the base endpoint. More...
 
void construct_default_body (char *data_packet, char *labels[], float readings[], int nvars)
 Parses label and readings arrays into an influxdb line protocol body. More...
 
uint8 send_readings (char *body, char *send_str, char *response_str, char *socket_dial_str, char *labels[], float readings[], uint8 nvars)
 Send readings to influxdb. More...
 
uint8 append_tags (char *main_tags, char *appended_label, char *appended_value)
 Append new tags to existing influxdb tags. More...
 
char * url_encode (char *str)
 Return a URL-encoded version of the input string. More...
 

Detailed Description

Declares the sensor subroutine, metadata updater, trigger updater, and parameter updater.

Author
Matt Bartos and Brandon Wong
Version
TODO
Date
2017-06-19

Function Documentation

uint8 append_tags ( char *  main_tags,
char *  appended_label,
char *  appended_value 
)

Append new tags to existing influxdb tags.

Parameters
main_tagsExisting tag string (comma-separated)
appended_labelTag label to append
appended_valueTag value to append
Returns
1
void construct_default_body ( char *  data_packet,
char *  labels[],
float  readings[],
int  nvars 
)

Parses label and readings arrays into an influxdb line protocol body.

Parameters
data_packetEmpty buffer to store POST request body
labelsBuffer to store labels corresponding to each trigger result
readingsBuffer to store trigger results as floating point values
nvarsNumber of variables (entries) in the readings array
Returns
null

Here is the caller graph for this function:

void construct_route ( char *  route,
char *  base,
char *  user,
char *  pass,
char *  database 
)

Constructs the route (URL) following the base endpoint.

Parameters
routeEmpty buffer to store route information
baseBase endpoint
userInfluxdb username
passInfluxdb password
databaseInfluxdb database
Returns
null

Here is the caller graph for this function:

uint8 execute_triggers ( char *  labels[],
float  readings[],
uint8 *  array_ix,
uint8  max_size 
)

Executes triggers and stores results into an array of labels and an array of readings.

Parameters
labelsArray to store labels corresponding to each trigger result
readingsArray to store trigger results as floating point values
array_ixArray index to label and readings
max_sizeMaximum size of label and reading arrays (number of entries)
Returns
(*array_ix) + number of entries filled

Here is the call graph for this function:

uint8 run_meta_subroutine ( char *  meid,
char *  send_str,
char *  response_str,
uint8  get_device_meid 
)

Runs update_meta and stores the results in an array of readings and labels.

Parameters
meidThe mobile equipment identificiation number for the cell module
send_strEmpty buffer to place request string
response_strEmpty buffer to store server response
get_device_meidWhether to re-read meid from cell module.
  • 0: Use current value of meid in memory
  • 1: Read meid from cell module and store in memory
Returns
1 if metadata updated successfully, and 0 otherwise

Here is the call graph for this function:

uint8 send_readings ( char *  body,
char *  send_str,
char *  response_str,
char *  socket_dial_str,
char *  labels[],
float  readings[],
uint8  nvars 
)

Send readings to influxdb.

Parameters
bodyEmpty buffer to hold message body
send_strEmpty buffer to hold request string
response_strEmpty buffer to hold server response
socket_dial_strEmpty buffer to hold string used in socket dial
labelsArray containing reading labels
readingsArray containing readings as floating point values
nvarsNumber of variables (entries) in the readings array
Returns
1 if data transmission was successful, otherwise 0.

Here is the call graph for this function:

int take_readings ( char *  labels[],
float  readings[],
uint8 *  array_ix,
uint8  take_average,
uint8  max_size 
)

Takes sensor readings and stores results into an array of labels and an array of readings.

Parameters
labelsArray to store labels corresponding to each reading
readingsArray to store readings as floating point values
array_ixArray index to label and readings
take_averageWhether to take average or not
  • 0: Take first valid reading
  • 1: Take average of valid readings
max_sizeMaximum size of label and reading arrays (number of entries) in buffer.
Returns
(*array_ix) + number of entries filled

Here is the call graph for this function:

int update_meta ( char *  meid,
char *  send_str,
char *  response_str 
)

Update values of node_id, node_user, node_pass, node_db on device based on current values stored on server.

Parameters
meidThe mobile equipment identificiation number for the cell module
send_strEmpty buffer to place request string
response_strEmpty buffer to store server response
get_device_meidWhether to re-read meid from cell module.
  • 0: Use current value of meid in memory
  • 1: Read meid from cell module and store in memory
Returns
(response_code - true_response_code). The value of response code is a sum of the following powers of two:
  • 1: node_id successfully updated
  • 2: user successfully updated
  • 4: pass successfully updated
  • 8: database successfully updated A response code of 15 indicates that all parameters were successfully updated. The true_reponse_code is 15. Thus, if all parameters are updated successfully, the function will return 0.

Here is the call graph for this function:

Here is the caller graph for this function:

void update_params ( char *  body,
char *  send_str,
char *  response_str 
)

Update values of onboard parameters, such as sleeptimer and flags such as ultrasonic_flag or valve_flag.

Parameters
bodyEmpty buffer to store request body
send_strEmpty buffer to store request string
response_strEmpty buffer to store server response
Returns
null

Here is the call graph for this function:

int update_triggers ( char *  body,
char *  send_str,
char *  response_str 
)

Update values of triggers, such as valve_trigger, autosampler_trigger and gps_trigger based on current values stored on server.

Parameters
bodyEmpty buffer to store request body
send_strEmpty buffer to store request string
response_strEmpty buffer to store server response
Returns
(response_code - true_response_code). The value of response code is a sum of the following powers of two:
  • 1: meta_trigger successfully updated
  • 2: autosampler_trigger successfully updated
  • 4: valve_trigger successfully updated
  • 8: valve_2_trigger successfully updated
  • 16: gps_trigger successfully updated A response code of 15 indicates that all parameters were successfully updated. The true_reponse_code is 31. Thus, if all parameters are updated successfully, the function will return 0.

Here is the call graph for this function:

char* url_encode ( char *  str)

Return a URL-encoded version of the input string.

Parameters
strString to URL-encode
Returns
URL-encoded string.

Here is the caller graph for this function:

uint8 zip_meta ( char *  labels[],
float  readings[],
uint8 *  array_ix,
uint8  max_size 
)

Inserts current value of meta_trigger into readings array.

Parameters
labelsArray to store labels corresponding to each trigger result
readingsArray to store trigger results as floating point values
array_ixArray index to label and readings
max_sizeMaximum size of label and reading arrays (number of entries)
Returns
(*array_ix) + number of entries filled

Here is the caller graph for this function:

uint8 zip_modem ( char *  labels[],
float  readings[],
uint8 *  array_ix,
uint8  max_size 
)

Inserts current values of connection_attempt_counter rssi and fer into readings array.

Parameters
labelsArray to store labels corresponding to each trigger result
readingsArray to store trigger results as floating point values
array_ixArray index to label and readings
max_sizeMaximum size of label and reading arrays (number of entries)
Returns
(*array_ix) + number of entries filled