# HG changeset patch # User William Welliver # Date 1496111725 14400 # Mon May 29 22:35:25 2017 -0400 # Node ID 8dae3d8ebb529ae21cf25743f14bdb3583b027e7 # Parent f364b54e18b036ef807161a6197b7885e743c1ea update to platformio diff --git a/.hgignore b/.hgignore new file mode 100644 --- /dev/null +++ b/.hgignore @@ -0,0 +1,5 @@ +.pioenvs +.piolibdeps +.idea +.DS_Store +CMakeListsPrivate.txt diff --git a/firmware/base_station/CMakeLists.txt b/firmware/base_station/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/firmware/base_station/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.2) +project(base_station) + +include(CMakeListsPrivate.txt) + +add_custom_target( + PLATFORMIO_BUILD ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion run + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_UPLOAD ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target upload + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_CLEAN ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target clean + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_TEST ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion test + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_PROGRAM ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target program + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_UPLOADFS ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion run --target uploadfs + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_UPDATE_ALL ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion update + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_custom_target( + PLATFORMIO_REBUILD_PROJECT_INDEX ALL + COMMAND ${PLATFORMIO_CMD} -f -c clion init --ide clion + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_executable(${PROJECT_NAME} ${SRC_LIST}) diff --git a/firmware/base_station/platformio.ini b/firmware/base_station/platformio.ini new file mode 100644 --- /dev/null +++ b/firmware/base_station/platformio.ini @@ -0,0 +1,17 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:diecimilaatmega328] +platform = atmelavr +board = diecimilaatmega328 +framework = arduino +lib_deps = +https://github.com/jcw/ethercard.git +;https://github.com/jcw/jeelib.git diff --git a/firmware/base_station/src/base_station.cpp b/firmware/base_station/src/base_station.cpp new file mode 100644 --- /dev/null +++ b/firmware/base_station/src/base_station.cpp @@ -0,0 +1,197 @@ +#include + + +#include +#include +#include + +#include +#include + +#if 0 +#include + +#endif + +#include + +void postData (uint8_t *dip, struct payload * pl); +static void addPayload (struct payload * data); + +#define WX_DATA_PORT 7656 + +#define gPB ether.buffer + +static byte* bufPtr; +/* + struct { + uint8_t station_id; + int16_t uptime; + int16_t temp; + int32_t pres; + float relhx; + float tempb; + float rainfall; + float windspeed; + float maxwindspeed; + char winddira; + char winddirb; word luxa; word luxb; word luxc;} payload; + */ + +struct payload { + char cookiea; + char cookieb; + char cookiec; + char cookied; + uint8_t station_id; + int16_t uptime; + int16_t temp; + int32_t pres; + float relhx; + float tempb; + float rainfall; + float windspeed; + float maxwindspeed; + char winddira; + char winddirb; + word luxa; + word luxb; + word luxc; + }; + +typedef struct payload wx_data; + +// typedef struct { int16_t temp; int32_t pres; } Payload; +int i = 0; +static byte mymac[] = { 0x74, 0x69, 0x69, 0x2d, 0x30, 0x31 }; + +byte Ethernet::buffer[700]; + +static byte dnstid_l; // a counter for transaction ID +#define DNSCLIENT_SRC_PORT_H 0xD2 + +#define soft_reset() \ +do \ +{ \ + wdt_enable(WDTO_15MS); \ + for(;;) \ + { \ + } \ +} while(0) + +// Function Pototype +//void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); + +// Function Implementation +/* +void wdt_init(void) +{ + MCUSR = 0; + wdt_disable(); + + return; +} +*/ +void setup() { + Serial.begin(57600); + Serial.println("\n[bmp085recv]\n"); + +// rf12_initialize(30, RF12_915MHZ, 5); + +// return; + + if(ether.begin(sizeof Ethernet::buffer, mymac) == 0) + { + Serial.println("failed to access Ethernet controller"); + } + if(!ether.dhcpSetup()) + { + Serial.println("DHCP failed"); + delay(5000); + void (*softReset) (void) = 0; //declare reset function @ address 0 + softReset(); + } + ether.printIp("IP: ", ether.myip); + ether.printIp("GW: ", ether.gwip); + + if(!ether.dnsLookup(PSTR("192.168.1.10"))) + { + Serial.println("DNS failed"); + delay(5000); + void (*softReset) (void) = 0; //declare reset function @ address 0 + softReset(); + } + ether.printIp("SRV: ", ether.hisip); + +// ether.registerPingCallback(gotPinged); +} + +void loop() { +//return; + if(rf12_recvDone() && rf12_crc == 0) +// if(rf12_len != sizeof(wx_data)) +// else + { + wx_data * data = (wx_data *) rf12_data; + Serial.print((int)data->station_id); + Serial.print(" BMP / RHumidity / Rain / Wind / Lux "); + Serial.print(data->cookiea); + Serial.print(data->cookieb); + Serial.print(data->cookiec); + Serial.print(data->cookied); + Serial.print(' '); + Serial.print((int)(data->uptime)); + Serial.print(": "); + Serial.print(data->temp); + Serial.print(' '); + Serial.print(data->pres); + Serial.print(" / "); + Serial.print(data->relhx); + Serial.print(' '); + Serial.print(data->tempb); + Serial.print(" / "); + Serial.print(data->rainfall); + Serial.print(" / "); + Serial.print(data->windspeed); + Serial.print(" / "); + Serial.print(data->winddira); +//if(data->winddirb) + Serial.print(data->winddirb); + Serial.print(data->maxwindspeed); + Serial.print(" / "); + Serial.print(data->luxa); + Serial.print(' '); + Serial.print(data->luxb); + Serial.print(' '); + Serial.println(data->luxc); + postData(ether.hisip, data); + // i++; + } +} + + void postData (uint8_t *dip, struct payload * pl) { + ++dnstid_l; // increment for next request, finally wrap + + ether.udpPrepare((DNSCLIENT_SRC_PORT_H << 8) | dnstid_l, + dip, WX_DATA_PORT); + memset(gPB + UDP_DATA_P, 1, sizeof(struct payload)); + + bufPtr = gPB + UDP_DATA_P; + addPayload(pl); + + ether.udpTransmit((bufPtr - gPB) - UDP_DATA_P); +} + +static void addToBuf (byte b) { + *bufPtr++ = b; +} + +static void addPayload (struct payload * data) { + int len = sizeof(struct payload); + byte * d; + + d = (byte *) data; + while (len-- > 0) + addToBuf(*d++); +} + diff --git a/libraries/WeatherSensorsI2C/WeatherSensorsI2C.cpp b/libraries/WeatherSensorsI2C/WeatherSensorsI2C.cpp --- a/libraries/WeatherSensorsI2C/WeatherSensorsI2C.cpp +++ b/libraries/WeatherSensorsI2C/WeatherSensorsI2C.cpp @@ -1,4 +1,4 @@ - +#include "Arduino.h" #include #include #include @@ -136,7 +136,7 @@ uint16_t result; Wire.beginTransmission(eWeatherSensorAddress); - Wire.send(command); + Wire.write(command); Wire.endTransmission(); delay(readDelay); @@ -147,8 +147,8 @@ } //Store the result - result = Wire.receive(); - result += ((Wire.receive()) << 8); + result = Wire.read(); + result += ((Wire.read()) << 8); return result; }