diff --git a/examples/api_test/api_test.ino b/examples/api_test/api_test.ino index 0546edc9..736a52da 100644 --- a/examples/api_test/api_test.ino +++ b/examples/api_test/api_test.ino @@ -1,20 +1,20 @@ #include "KiteLib.h" ESP8266 wifi = Kite.ModuleA; -//SX1278 lora = Kite.ModuleB; +SX1278 lora = Kite.ModuleB; //HC05 bluetooth = Kite.ModuleB; -//Packet pack("01:23:45:67:89:AB:CD:EF", "Hello World! (by LoRa)"); +Packet pack("01:23:45:67:89:AB:CD:EF", "Hello World! (by LoRa)"); void setup() { Serial.begin(9600); Serial.print("[ESP8266] Connecting ... "); - uint8_t state = wifi.begin(9600); + byte state = wifi.begin(9600); if(state == ERR_NONE) { Serial.println("success!"); } else { - Serial.print("failed, code "); + Serial.print("failed, code 0x"); Serial.println(state, HEX); } @@ -23,29 +23,43 @@ void setup() { if(state == ERR_NONE) { Serial.println("success!"); } else { - Serial.print("failed, code "); + Serial.print("failed, code 0x"); Serial.println(state, HEX); } Serial.print("[ESP8266] Sending GET request ... "); String response; - uint16_t http_code = wifi.HttpGet("http://www.httpbin.org/ip", response); + int http_code = wifi.HttpGet("http://www.httpbin.org/ip", response); if(http_code == 200) { Serial.println("success!"); Serial.println("[ESP8266] Response:\n"); Serial.println(response); } else { - Serial.print("failed, code "); + Serial.print("failed, code 0x"); Serial.println(http_code, HEX); } - //lora.begin(); + Serial.print("[SX1278] Initializing ... "); + state = lora.begin(); + if(state == ERR_NONE) { + Serial.println("success!"); + } else { + Serial.print("failed, code 0x"); + Serial.println(state, HEX); + } //bluetooth.begin(9600); } void loop() { - //lora.transmit(pack); + Serial.print("[SX1278] Transmitting packet ... "); + byte state = lora.transmit(pack); + if(state == ERR_NONE) { + Serial.println("success!"); + } else { + Serial.print("failed, code 0x"); + Serial.println(state, HEX); + } //bluetooth.println("Hello World! (by Blueooth)"); diff --git a/src/ESP8266.cpp b/src/ESP8266.cpp index f74194e2..d51abdec 100644 --- a/src/ESP8266.cpp +++ b/src/ESP8266.cpp @@ -11,7 +11,7 @@ uint8_t ESP8266::begin(long speed) { _mod->init(USE_UART, INT_NONE); _mod->ATemptyBuffer(); if(!_mod->ATsendCommand("AT")) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } return(ERR_NONE); } @@ -19,7 +19,7 @@ uint8_t ESP8266::begin(long speed) { uint8_t ESP8266::reset() { // send the reset command if(!_mod->ATsendCommand("AT+RST")) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } // wait for the module to start @@ -35,13 +35,13 @@ uint8_t ESP8266::reset() { } } - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } uint8_t ESP8266::join(const char* ssid, const char* password) { // set mode to station + soft AP if(!_mod->ATsendCommand("AT+CWMODE_CUR=3")) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } // reset the module @@ -57,12 +57,12 @@ uint8_t ESP8266::join(const char* ssid, const char* password) { cmd += password; cmd += "\""; if(!_mod->ATsendCommand(cmd)) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } // disable multiple connection mode if(!_mod->ATsendCommand("AT+CIPMUX=0")) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } return(ERR_NONE); @@ -204,12 +204,12 @@ uint8_t ESP8266::send(String data) { String cmd = "AT+CIPSEND="; cmd += data.length(); if(!_mod->ATsendCommand(cmd)) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } // send data if(!_mod->ATsendCommand(data)) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } return(ERR_NONE); @@ -238,14 +238,14 @@ uint8_t ESP8266::openTransportConnection(const char* host, const char* protocol, cmd += "\","; cmd += port; if(!_mod->ATsendCommand(cmd)) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } return(ERR_NONE); } uint8_t ESP8266::closeTransportConnection() { if(!_mod->ATsendCommand("AT+CIPCLOSE")) { - return(ERR_UNKNOWN); + return(ERR_AT_FAILED); } return(ERR_NONE); } diff --git a/src/TypeDef.h b/src/TypeDef.h index 6761aebf..c113e423 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -37,23 +37,25 @@ // SX1278/SX1272 error codes #define ERR_CHIP_NOT_FOUND 0x01 #define ERR_EEPROM_NOT_INITIALIZED 0x02 -#define ERR_PACKET_TOO_LONG 0x10 -#define ERR_RX_TIMEOUT 0x20 -#define ERR_CRC_MISMATCH 0x21 -#define ERR_INVALID_BANDWIDTH 0x30 -#define ERR_INVALID_SPREADING_FACTOR 0x31 -#define ERR_INVALID_CODING_RATE 0x32 -#define ERR_INVALID_BIT_RANGE 0x40 +#define ERR_PACKET_TOO_LONG 0x03 +#define ERR_TX_TIMEOUT 0x04 +#define ERR_RX_TIMEOUT 0x05 +#define ERR_CRC_MISMATCH 0x06 +#define ERR_INVALID_BANDWIDTH 0x07 +#define ERR_INVALID_SPREADING_FACTOR 0x08 +#define ERR_INVALID_CODING_RATE 0x09 +#define ERR_INVALID_BIT_RANGE 0x10 // ESP8266 error codes -#define ERR_URL_MALFORMED 0x01 -#define ERR_RESPONSE_MALFORMED_AT 0x02 -#define ERR_RESPONSE_MALFORMED 0x03 +#define ERR_AT_FAILED 0x01 +#define ERR_URL_MALFORMED 0x02 +#define ERR_RESPONSE_MALFORMED_AT 0x03 +#define ERR_RESPONSE_MALFORMED 0x04 enum Slot {SlotA, SlotB}; -enum Bandwidth {BW_7_80_KHZ, BW_10_40_KHZ, BW_15_60_KHZ, BW_20_80_KHZ, BW_31_25_KHZ, BW_41_70_KHZ, BW_62_50_KHZ, BW_125_00_KHZ, BW_250_00_KHZ, BW_500_00_KHZ, }; +enum Bandwidth {BW_7_80_KHZ, BW_10_40_KHZ, BW_15_60_KHZ, BW_20_80_KHZ, BW_31_25_KHZ, BW_41_70_KHZ, BW_62_50_KHZ, BW_125_00_KHZ, BW_250_00_KHZ, BW_500_00_KHZ}; enum SpreadingFactor {SF_6, SF_7, SF_8, SF_9, SF_10, SF_11, SF_12}; enum CodingRate {CR_4_5, CR_4_6, CR_4_7, CR_4_8};