Code Monkey home page Code Monkey logo

weather-station-node-c's Introduction

Important preamble

THIS IS NOT OPEN SOURCE SOFTWARE ⁠— See NO_LICENSE.TXT for further information.

The purpose of publishing this code is to demonstrate a modular approach to a design of embedded 'C' drivers and application code for an Internet-connected nodal device.

Not all components of the final build are included here. The missing elements are third-party commercial products that have been licensed for use in the end-product. Some details of the client implementation have also been redacted (see below).

Weather station node controller

These 'C' code modules are drawn from my commercial design in 2006-7 for a node controller to connect a weather station over the Internet to a central server for regular relaying of weather data. With the agreement of my client, I have published my code with implementation-specific details replaced by placeholders (marked with "%%" in code files).

The processing platform for this node controller is a RabbitCore® RCM3720 module. The development toolchain was the Softools Rabbit 'C' compiler and associated libraries.

See References section for further information.

Quick links

Overall purpose of node controller

Each node controller is paired with a weather station (from Davis Instruments Corp.) at a series of locations. The node controller connects to the weather station via a serial interface and to the local area network via an Ethernet cable. The weather station is configured to collect data from the weather station at periodic intervals and relay these data over the Internet to a central server using a subset of the HTTP protocol (v1.1).

The node controller can be monitored and configured either over a direct serial connection or remotely (via a UDP connection to a Windows PC elsewhere on the local network or beyond). The node controller also includes the capability for remote firmware updating on demand from a binary file held on the central server. Configuration parameters for the node controller are held in non-volatile memory (EEPROM for static data and battery-backed RAM for dynamic data) so that the node controller can recover readily from a power interruption.

Hierarchy of code modules

The code modules in this repository fall into the following hierarchy:

Hierarchy of weather station code modules

Descriptions of code modules

My code modules (included)

The following code files have been written by the author and are therefore included here.

wx_main.c module (and wx_main.h header)

The wx_main module contains the main() entry point for the 'C' application. It is responsible for initialising the system and starting up the supporting processes (see hierarchy tree). The header file passes out a few system-wide declarations needed by other modules.

lan.c module (and lan.h header)

The lan module is responsible for starting up, shutting down and managing the LAN interface to the Internet over the Ethernet connection. The header file exposes the associated constant, variable and function declarations needed by other modules.

menu.c module (and menu.h header)

The menu module provides the configuration menu for management of the node controller by a directly or remotely connected technician. The header file exposes the associated constant and function declarations needed by other modules.

stack_check.c module (and stack_check.h header)

The stack_check module contains a pair of utility functions for measurement of the maximum depth of stack used by the node controller during its operation (too much stack usage could lead to random system crashes). The header file exposes the associated constant and function declarations needed by other modules to set up and make the stack depth measurement.

download.c module (and download.h header)

The download module is a wrapper around the remote firmware updating services provided by the third-party WEB_DL module (see later below). The header file exposes the associated constant and function declarations needed by other modules.

tasks.c module (and tasks.h header)

The tasks module contains the top-level loop that calls repeatedly the state machines for polling of the weather station (davis module as below) and posting of data to the central server (post_client module as below). The header file exposes the associated constant and function declarations needed by other modules to set up the loop and call an iteration of it.

post_client.c module (and post_client.h header)

The post_client module provides the state machine for posting of data to the central server. The header file exposes the associated constant and function declarations needed by other modules to initialise the state machine, call an iteration and otherwise interact with it.

davis.c module (and davis.h header)

The davis module contains the state machine for polling and collection of data from the weather station. The header file exposes the associated constant, variable and function declarations needed by other modules to initialise the state machine, call an iteration and otherwise interact with it.

crc.c module (and crc.h header)

The crc module provides a function to calculate the 16-bit CRC for a block of data according to the CCITT standard, as adopted by Davis Instruments Corp. for the Vantage Pro 2™ weather station. The header file exposes the function declaration needed by the davis module.

bb_vars.c module (and bb_vars.h header)

The bb_vars module contains a utility function to initialise the battery backed RAM in the Rabbit module for first use, or after a change to the firmware version. The function checks for a fingerprint value in battery backed RAM and takes no further action if this is present and the firmware version number is unchanged. The header file exposes the declarations for the utility function and all of the variables that are held in battery backed RAM.

report.c module (and report.h header)

The report module provides a set of utility functions to send formatted reporting output to a directly or remotely connected debug console. The module supports both a "terse" and "verbose" output mode, as selected by a configuration DIP switch and a value passed to the reporting function to specify whether the report is informational or a problem indication ("terse" mode suppresses some information-only output). Each line of report output is prefixed by a shortform indication of its functional source (e.g. "NET", "SER", "UP"). The header file exposes the associated constant and function declarations needed by other modules.

eeprom.c module (and eeprom.h header)

The eeprom module contains a set of utility functions to read, write and compare system configuration parameters stored in EEPROM. These configuration parameters are segregated into functional blocks with integrity safeguards to ensure that an error is returned if the block has not been initialised or has become corrupted. The header file exposes the associated constant, variable and function declarations needed by other modules. The eeprom module depends on the i2c module (see below) to access a 24LC64 I2C Serial EEPROM.

i2c-delta.c module (and i2c-delta.h header)

The i2c-delta module provides an incremental set of definitions and declarations that must be added to the standard I2C bus library to create amalgamated i2c.c and i2c.h files for the project build. The standard I2C bus library is the one included with Dynamic C as provided by Rabbit Semiconductor Inc. and included with the licence for the Softools Rabbit 'C' compiler. This I2C.LIB must first be unpacked using the Softools conversion tool to create the i2c.c and i2c.h files, to which the contents of these i2c-delta.c and i2c-delta.h modules must then be added.

rtc_utils.c module (and rtc_utils.h header)

The rtc_utils module contains a set of utility functions to support the real-time clock in the Rabbit module. The header file exposes the associated variable and function declarations needed by other modules.

wx_board.c module (and wx_board.h header)

The wx_board module provides a set of functions to support the external input/output hardware connected to the Rabbit module, including status LED outputs, DIP switch inputs and serial interface status lines. The header file exposes the associated constant, variable and function declarations needed by other modules.

timeout.h module

The timeout.h module (header file only) contains a set of #define macros to enable timeouts of various lengths and granularity (milliseconds or seconds) to be set and checked by other modules.

Third-party files (not included)

The following third-party files are required to complete the build but are not included here.

Cstart module (.asm file)

This third-party module is part of the Softools Rabbit 'C' compiler library. It handles the low-level startup of the Rabbit module from power-up or reset, then passes control to the 'C' main() function.

The Cstart module needs to be linked into the overall project build.

SCRabbit module (.lib file)

This third-party module is part of the Softools Rabbit 'C' compiler library. It provides a set of functions specifically associated with the Rabbit module (as distinct from standard 'C' libraries).

The SCRabbit module needs to be linked into the overall project build.

Bootp_01 module (.c file)

This third-party module is part of the Softools Rabbit 'C' compiler library. It provides support functions for setting up the Ethernet and LAN interfaces on the local network, including the DHCP protocol for automatic assignment of IP address and associated network parameters.

The Bootp_01 module does not directly expose variables and functions to application code, but needs to be linked into the overall project build.

STCPIP-DHCP module (.lib file)

This third-party module is part of the Softools Rabbit 'C' compiler library. It provides support functions for setting up the Ethernet and LAN interfaces on the local network, including the DHCP protocol for automatic assignment of IP address and associated network parameters.

The STCPIP-DHCP module does not directly expose variables and functions to application code, but needs to be linked into the overall project build.

udpdebug module (.c and .h files)

This third-party module is a free library offered by SHDesigns that can be downloaded from here. It enables the debug console output from the weather station node controller to be accessed over a UDP connection from a Windows PC on the local network (or potentially at a remote location using UDP tunneling). The PC needs to be running the corresponding UDP Debug application that is supplied with the library.

The udpdebug module exposes the following variables and functions in its header file (udpdebug.h):

extern char debug_autocr;
extern FILE debug_stdio[1];

int debug_init(int ena);
int debug_kbhit(void);
int near debug_getchar(void);
void near debug_putchar(char c);
int debug_tick(void);

WEB_DL module (.c and .h files)

This third-party module is a commercial library offered by SHDesigns that manages the process of remote firmware updates. The library enables the weather station node controller to poll for a firmware update hosted on the central server. If an update is available, then the corresponding binary file can be downloaded into a holding memory and then flashed into program memory. The library includes safeguards to protect the node controller from a failed or partial download, or various other error conditions during the update process. Further information is available here.

The WEB_DL module exposes the following variables and functions in its header file (WEB_DL.h):

extern unsigned _sector_size;

void set_flash_start(long addr);
int write_sector(long block,char * buff, int bsize);
int CheckWebVersion(char * url, char * server_ip, unsigned port, long * version);
int GetWebUpdate(void);

References

Toolchain and libraries

Rabbit core module

Weather station

Other references

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.