able to subscribe for >10hrs and still running
Dependencies: ADE7758_v1 Crypto DHT11 MQTT MbedJSONValue SDFileSystem SPI_TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src tuanpm
Fork of PB_emma_controller_mbed_src by
emmaCode.h
00001 #ifndef MBED_EMMACODE_H 00002 #define MBED_EMMACODE_H 00003 00004 #include "mbed.h" 00005 #include "espduino.h" //wifi mqtt 00006 #include "mqtt.h" //wifi mqtt 00007 #include "rest.h" //wifi rest 00008 #include "MQTTClient.h" //eth mqtt 00009 #include "MQTTEthernet.h" //eth mqtt 00010 #include "MbedJSONValue.h" //json 00011 #include "SDFileSystem.h" //sd card 00012 #include "Crypto.h" //hash calculation 00013 #include "cmsis_os.h" //threads 00014 #include "ade7758.h" //ade7758 00015 #include "SPI_TFT_ILI9341.h" //lcd 00016 #include "Touch.h" //touch 00017 #include "Arial12x12.h" //font 00018 #include "SetRTC.h" //rtc 00019 #include "DHT11.h" //dht11 00020 #include <string> 00021 00022 //platform 00023 #if defined TARGET_NUCLEO_F103RB 00024 #define BASE_ADDR 0x1FFFF7E8 00025 #elif defined TARGET_NUCLEO_F401RE 00026 #define BASE_ADDR 0x1FFF7A10 00027 #endif 00028 00029 #define MAXTOKEN 64 00030 00031 //mode 00032 #define MODE_WIFI_CONFIG 0x00 //wifi config 00033 #define MODE_SETTINGS 0x01 //settings 00034 #define MODE_REGISTER 0x02 //registration 00035 #define MODE_OPERATION 0x03 //operational 00036 #define MODE_FIRMWARE_DOWNLOAD 0x04 //firmware download 00037 00038 //interface 00039 #define IF_WIFI 0x00 00040 #define IF_ETH 0x01 00041 #define IF_GPRS 0x02 00042 00043 //wifi 00044 #define ESP_BAUD 19200 00045 00046 //mqtt 00047 #define MQTT_MAX_PACKET_SIZE 250 //for eth 00048 #define MQTT_HOST "192.168.131.200" 00049 #define MQTT_PORT 1883 00050 00051 //eth rest 00052 #define SERVER_PORT 80 00053 00054 //nodes and remote 00055 #define REMOTE_TCP_PORT 16038 00056 #define NODES_MAX 5 00057 #define NODES_INVALID 99 00058 00059 //emma server 00060 #define EMMA_SERVER_HOST "192.168.131.200" 00061 #define EMMA_SERVER_PORT 8080 00062 00063 //ade7758 offset 00064 #define AIRMSOFFSET 0xFB1 00065 #define BIRMSOFFSET 0xFB0 00066 #define CIRMSOFFSET 0xFB1 00067 #define AVRMSOFFSET 0xFFB 00068 #define BVRMSOFFSET 0x2 00069 #define CVRMSOFFSET 0xFFF 00070 00071 //threshold 00072 #define VRMSTHRESHOLD 250 00073 #define WATTTHRESHOLD 10000 00074 00075 /*start lcd and touch*/ 00076 int emmaModeSelection(void); 00077 /*end lcd and touch*/ 00078 00079 /*start emma mode*/ 00080 void emmaInit(int mode); 00081 void emmaModeWiFiConfig(void); 00082 void emmaModeSettings(void); 00083 void emmaModeRegister(void); 00084 void emmaModeOperation(void); 00085 void emmaModeFirmwareDownload(void); 00086 /*end emma mode*/ 00087 00088 /*start energy related*/ 00089 void energyThread(void const*); 00090 void checkVoltagePower(void); 00091 /*end energy related*/ 00092 00093 /*start wifi mqtt*/ 00094 void mqttConnected(void* response); 00095 void mqttDisconnected(void* response); 00096 /*end wifi mqtt*/ 00097 00098 /*start wifi rest*/ 00099 void rxInterrupt(void); 00100 void checkRxBuffer(void); 00101 /*end wifi rest*/ 00102 00103 /*start eth mqtt*/ 00104 int publish(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack); 00105 void ethMQTTMessageArrived(MQTT::MessageData& md); 00106 int ethMQTTConnect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack); 00107 void ethMQTTAttemptConnect(MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE>* client, MQTTEthernet* ipstack); 00108 /*end eth mqtt*/ 00109 00110 /*start emma settings*/ 00111 string getUID(void); 00112 string readSetting(string parameter); 00113 bool writeSetting(string parameter, string value); 00114 /*end emma settings*/ 00115 00116 /*start nodes*/ 00117 string readNodeIP(string macAddr); 00118 string readNodeCmd(string dType, string cmd); 00119 string *readNodeList(void); 00120 string wifiGetNodeTemp(string macAddr); 00121 /*end nodes*/ 00122 00123 /*start emma connection function*/ 00124 string ethGET(string host, int port, string data); 00125 /*end emma connection function*/ 00126 00127 /*start emma private function*/ 00128 //void connectedIface(void); 00129 void isEthAvailable(void); 00130 void isEthConnected(void); 00131 void isWiFiConnected(void); 00132 void isGprsConnected(void); 00133 void addChar(char *s, char c); 00134 void rcvReply(char *r, int to); 00135 string calculateMD5(string text); 00136 bool writeFirmwareHexToChar(string value); 00137 bool clearFirmware(void); 00138 /*end emma private function*/ 00139 00140 #endif
Generated on Sun Jul 17 2022 01:06:43 by 1.7.2