Open Storm
Functions | Variables
data.c File Reference

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

#include "data.h"
#include "gps.h"
#include "extern.h"
#include "config.h"
Include dependency graph for data.c:

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 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 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 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...
 

Variables

char node_id [20] = DEFAULT_NODE_ID
 
char user [20] = DEFAULT_HOME_USER
 
char pass [50] = DEFAULT_HOME_PASS
 
char database [20] = DEFAULT_HOME_DB
 
char meta_user [20] = DEFAULT_META_USER
 
char meta_pass [50] = DEFAULT_META_PASS
 
char meta_database [20] = DEFAULT_META_DB
 
int main_port = DEFAULT_HOME_PORT
 
char main_host [100] = DEFAULT_HOME_HOST
 
char main_tags [200] = DEFAULT_GLOBAL_TAGS
 
char write_route [60] = ""
 
char main_query [300] = {'\0'}
 
int service_flag = 1u
 
int sleeptimer = SLEEPTIMER
 
int max_conn_attempts = MAX_CONNECTION_ATTEMPTS
 
uint8 enable_ssl_config = ENABLE_SSL_CONFIG
 
uint8 enable_ssl_sec_config = ENABLE_SSL_SEC_CONFIG
 
uint8 ssl_enabled = SSL_ENABLED
 
int modem_flag = MODEM_FLAG
 
int meta_flag = META_FLAG
 
int vbat_flag = VBAT_FLAG
 
int gps_flag = GPS_FLAG
 
int ultrasonic_flag = ULTRASONIC_FLAG
 
int ultrasonic_2_flag = ULTRASONIC_2_FLAG
 
int senix_flag = SENIX_FLAG
 
int optical_rain_flag = OPTICAL_RAIN_FLAG
 
int decagon_flag = DECAGON_FLAG
 
int autosampler_flag = AUTOSAMPLER_FLAG
 
int valve_flag = VALVE_FLAG
 
int valve_2_flag = VALVE_2_FLAG
 
int atlas_wq_flag = ATLAS_WQ_FLAG
 
int autosampler_trigger = AUTOSAMPLER_TRIGGER
 
int valve_trigger = VALVE_TRIGGER
 
int valve_2_trigger = VALVE_2_TRIGGER
 
int meta_trigger = META_TRIGGER
 
int gps_trigger = GPS_TRIGGER
 
int vbat_loops = VBAT_LOOPS
 
int ultrasonic_loops = ULTRASONIC_LOOPS
 
int optical_rain_loops = OPTICAL_RAIN_LOOPS
 
int decagon_loops = DECAGON_LOOPS
 
int connection_attempt_counter = 0
 
int rssi = 0u
 
int fer = 0u
 
uint8 bottle_count = 0
 
int valve = 0
 
uint8 array_ix = 0u
 

Detailed Description

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

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

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