diff --git a/Network Module Manual - Code Rev 20210221 1826.odt b/Network Module Manual - Code Rev 20210412 1333.docx similarity index 62% rename from Network Module Manual - Code Rev 20210221 1826.odt rename to Network Module Manual - Code Rev 20210412 1333.docx index ccde996..a97b7dc 100644 Binary files a/Network Module Manual - Code Rev 20210221 1826.odt and b/Network Module Manual - Code Rev 20210412 1333.docx differ diff --git a/Network Module Manual - Code Rev 20210221 1826.docx b/Network Module Manual - Code Rev 20210412 1333.odt similarity index 63% rename from Network Module Manual - Code Rev 20210221 1826.docx rename to Network Module Manual - Code Rev 20210412 1333.odt index 6f01c3d..c1d4834 100644 Binary files a/Network Module Manual - Code Rev 20210221 1826.docx and b/Network Module Manual - Code Rev 20210412 1333.odt differ diff --git a/Network Module Manual - Code Rev 20210221 1826.pdf b/Network Module Manual - Code Rev 20210412 1333.pdf similarity index 68% rename from Network Module Manual - Code Rev 20210221 1826.pdf rename to Network Module Manual - Code Rev 20210412 1333.pdf index 348a4d9..73c6d96 100644 Binary files a/Network Module Manual - Code Rev 20210221 1826.pdf and b/Network Module Manual - Code Rev 20210412 1333.pdf differ diff --git a/NetworkModule/.Idea_Groups/Vector_File.grp b/NetworkModule/.Idea_Groups/Vector_File.grp index 5e9643c..e98043b 100644 --- a/NetworkModule/.Idea_Groups/Vector_File.grp +++ b/NetworkModule/.Idea_Groups/Vector_File.grp @@ -1,5 +1,5 @@ # Group File Created by IDEA # Project: -# Sun Feb 21 11:31:10 2021 +# Mon Apr 12 07:55:28 2021 # "networkmodule_vector.o" diff --git a/NetworkModule/.Idea_Temp/COBJ.TMP b/NetworkModule/.Idea_Temp/COBJ.TMP index 52e20fd..cccef5b 100644 --- a/NetworkModule/.Idea_Temp/COBJ.TMP +++ b/NetworkModule/.Idea_Temp/COBJ.TMP @@ -4,17 +4,17 @@ header: executable format processor number 6, type 3 12 sections -580 symbols -5823 debug symbols +568 symbols +5478 debug symbols sections: .vector: hilo code, at address 0x8000 128 data bytes (0x0080) .const: hilo code, at address 0x8080 - 7217 data bytes (0x1c31) -.text: hilo code, at address 0x9cb1 - 23774 data bytes (0x5cde) + 7215 data bytes (0x1c2f) +.text: hilo code, at address 0x9caf + 23458 data bytes (0x5ba2) .eeprom: hilo, at address 0x4000 128 data bytes (0x0080) .bsct: no attribute, at address 0x0 @@ -26,191 +26,177 @@ sections: .data: hilo, at address 0xa 8 data bytes (0x0008) .bss: bss hilo, at address 0x12 - 1456 reserved bytes (0x05b0) + 1365 reserved bytes (0x0555) .iconst: bss hilo, at address 0x5fe 2 reserved bytes (0x0002) .debug: hilo, at address 0x0 - 83054 data bytes (0x1446e) + 88978 data bytes (0x15b92) .info.: no attribute, at address 0x0 - 3537 data bytes (0x0dd1) + 3609 data bytes (0x0e19) symbols: -__memory: 000005c2 section .bss defined public -c_ftoi: 0000f664 section .text defined public -___mqtt_pack_uint16: 0000df09 section .text defined public -___mqtt_unpack_uint16: 0000df2d section .text defined public -___mqtt_recv: 0000d56d section .text defined public -c_uitof: 0000f964 section .text defined public -c_itoly: 0000f6f5 section .text defined public -_mqtt_sync: 0000d073 section .text defined public -_mqtt_unpack_response: 0000de9f section .text defined public -_mqtt_unpack_connack_response: 0000d9b8 section .text defined public -_mqtt_unpack_publish_response: 0000daf2 section .text defined public -_mqtt_unpack_suback_response: 0000db7b section .text defined public -_memmove: 0000f4aa section .text defined public -_uip_ipchksum: 0000e570 section .text defined public -_uip_tcpchksum: 0000e5d6 section .text defined public +__memory: 00000567 section .bss defined public +___mqtt_recv: 0000d528 section .text defined public +c_itoly: 0000f566 section .text defined public +_mqtt_sync: 0000d030 section .text defined public +_mqtt_unpack_response: 0000de52 section .text defined public +_mqtt_unpack_connack_response: 0000d96b section .text defined public +_mqtt_unpack_publish_response: 0000daa5 section .text defined public +_mqtt_unpack_suback_response: 0000db2e section .text defined public +_memmove: 0000f460 section .text defined public +_uip_ipchksum: 0000e511 section .text defined public +_uip_tcpchksum: 0000e577 section .text defined public c_y: 00000007 section .ubsct defined public zpage -c_lgursh: 0000f7b3 section .text defined public -c_lgsbc: 0000f79d section .text defined public +c_lgsbc: 0000f72b section .text defined public _stored_EEPROM_revision1: 00004015 section .eeprom defined public -_check_mqtt_server_arp_entry: 0000f3b2 section .text defined public +_check_mqtt_server_arp_entry: 0000f352 section .text defined public _stack_limit1: 000005ff section .iconst defined public _stored_unused1: 00004014 section .eeprom defined public -_ON_OFF_word_new1: 000001f4 section .bss defined public +_ON_OFF_word_new1: 0000019a section .bss defined public _stored_unused3: 0000404c section .eeprom defined public -_uip_listenports: 000002cd section .bss defined public +_uip_listenports: 00000272 section .bss defined public _stored_unused4: 0000404d section .eeprom defined public -c_divul: 0000f7fe section .text defined public -_check_restart_reboot: 0000cc49 section .text defined public -_reboot: 0000cdca section .text defined public -___mqtt_next_pid: 0000d0a9 section .text defined public +c_divul: 0000f5f8 section .text defined public +_check_restart_reboot: 0000cc06 section .text defined public +_reboot: 0000cd87 section .text defined public +___mqtt_next_pid: 0000d066 section .text defined public _stored_unused5: 0000404e section .eeprom defined public -_uip_buf: 00000398 section .bss defined public -_mqtt_sendbuf: 00000228 section .bss defined public -_init_IWDG: 0000ce10 section .text defined public +_init_IWDG: 0000cdcd section .text defined public _stored_prior_config: 00004050 section .eeprom defined public -_mqtt_close_tcp: 000001a1 section .bss defined public -_mqtt_start: 00000128 section .bss defined public -_restart: 0000cd83 section .text defined public -_mqtt_sanity_ctr: 00000124 section .bss defined public -_check_DS18B20_ctr: 000000e5 section .bss defined public -___mqtt_pack_str: 0000df4a section .text defined public -_uip_arp_arpin: 0000f1b8 section .text defined public -_mqtt_mq_clean: 0000dd15 section .text defined public -_uip_conns: 000002ee section .bss defined public -_check_reset_button: 0000cf55 section .text defined public -_topic_base: 000000ee section .bss defined public -_mqtt_subscribe: 0000d296 section .text defined public -_unlock_eeprom: 0000c5b1 section .text defined public -_lock_eeprom: 0000c5c1 section .text defined public -_uip_init_stats: 0000e6a3 section .text defined public -_preload_alphas: 0000b522 section .text defined public -_check_alphas: 0000b52f section .text defined public -c_lumd: 0000f8fa section .text defined public -_clear_saved_postpartial_all: 0000b508 section .text defined public -_HttpDCall: 0000ab6e section .text defined public -_periodic_timer_expired: 0000e457 section .text defined public -_t100ms_timer_expired: 0000e487 section .text defined public -_mqtt_outbound_timer_expired: 0000e467 section .text defined public -_mqtt_timer_expired: 0000e477 section .text defined public -_arp_timer_expired: 0000e497 section .text defined public -_connack_received: 000002b5 section .bss defined public -_suback_received: 000002b4 section .bss defined public -_publish_pinstate_all: 0000c471 section .text defined public -_mqtt_pal_sendall: 0000df9b section .text defined public -_mqtt_pal_recvall: 0000e26b section .text defined public -_uip_TcpAppHubCall: 0000f440 section .text defined public -_code_revision: 00009a27 section .const defined public -_ps: 00009689 section .const defined public -c_eewrc: 0000f53f section .text defined public -_uip_flags: 000002e9 section .bss defined public -_connect_flags: 00000171 section .bss defined public -_saved_postpartial_previous: 0000006b section .bss defined public -_adjust_template_size: 0000a54f section .text defined public +_mqtt_close_tcp: 00000147 section .bss defined public +_mqtt_start: 000000f4 section .bss defined public +_restart: 0000cd40 section .text defined public +_mqtt_sanity_ctr: 000000f1 section .bss defined public +_check_DS18B20_ctr: 0000008a section .bss defined public +___mqtt_pack_str: 0000defd section .text defined public +_uip_process: 0000e68b section .text defined public +_uip_arp_arpin: 0000f158 section .text defined public +_mqtt_mq_clean: 0000dcc8 section .text defined public +_uip_conns: 00000293 section .bss defined public +_check_reset_button: 0000cf12 section .text defined public +_topic_base: 000000bb section .bss defined public +_mqtt_subscribe: 0000d253 section .text defined public +_unlock_eeprom: 0000c56e section .text defined public +_lock_eeprom: 0000c57e section .text defined public +c_lumd: 0000f7a1 section .text defined public +_HttpDCall: 0000ac88 section .text defined public +_periodic_timer_expired: 0000e3f8 section .text defined public +_t100ms_timer_expired: 0000e428 section .text defined public +_mqtt_outbound_timer_expired: 0000e408 section .text defined public +_mqtt_timer_expired: 0000e418 section .text defined public +_arp_timer_expired: 0000e438 section .text defined public +_connack_received: 0000025b section .bss defined public +_suback_received: 0000025a section .bss defined public +_publish_pinstate_all: 0000c43d section .text defined public +_mqtt_pal_sendall: 0000df4e section .text defined public +_uip_TcpAppHubCall: 0000f3e0 section .text defined public +_mac_string: 0000014c section .bss defined public +_show_temperature_string: 0000ac22 section .text defined public +_update_mac_string: 0000c95a section .text defined public +___mqtt_ping: 0000d2d2 section .text defined public +_uip_flags: 0000028e section .bss defined public +_connect_flags: 00000139 section .bss defined public _current_webpage: 00000047 section .bss defined public +_update_debug_storage1: 0000d003 section .text defined public +_htons: 0000efb9 section .text defined public +_parse_tail: 0000004a section .bss defined public +_hex2int: 0000a761 section .text defined public +_two_hex2int: 0000a781 section .text defined public +_auto_pub_count: 000000ba section .bss defined public +_mqttclient: 00000111 section .bss defined public +_ON_OFF_word_sent: 00000196 section .bss defined public +_adjust_template_size: 0000a605 section .text defined public +_break_while: 00000048 section .bss defined public _stored_devicename: 00004000 section .eeprom defined public _stored_mqtt_username: 00004035 section .eeprom defined public -_Pending_devicename: 000001ca section .bss defined public -_Pending_mqtt_username: 0000017d section .bss defined public -_strlen: 0000f50f section .text defined public -_uip_listen: 0000e6a4 section .text defined public -_uip_len: 00000394 section .bss defined public +_Pending_devicename: 00000170 section .bss defined public +_Pending_mqtt_username: 000000a6 section .bss defined public +_parse_local_buf: 0000b5a1 section .text defined public +_uip_buf: 0000033d section .bss defined public +_mqtt_sendbuf: 000001ce section .bss defined public +_strlen: 0000f4d8 section .text defined public +_uip_listen: 0000e644 section .text defined public +_uip_len: 00000339 section .bss defined public _stored_unused6: 0000404f section .eeprom defined public -_uip_slen: 000002d5 section .bss defined public -_stored_mqtt_password: 00004040 section .eeprom defined public -_saved_postpartial: 0000008f section .bss defined public -_Pending_mqtt_password: 00000172 section .bss defined public -_Invert_word: 000001ee section .bss defined public -_ON_OFF_word: 000001f6 section .bss defined public -c_eewrd: 0000f572 section .text defined public -c_rtol: 0000f927 section .text defined public -_Port_Httpd: 0000019d section .bss defined public -_saved_nparseleft: 000000b3 section .bss defined public -c_ftol: 0000f66a section .text defined public -c_ludv: 0000f7d3 section .text defined public -_alpha: 00000048 section .bss defined public -_hex2int: 0000a692 section .text defined public -_auto_pub_count: 000000ea section .bss defined public -_mqttclient: 00000145 section .bss defined public -_ON_OFF_word_sent: 000001f0 section .bss defined public -_int2hex: 0000a6b2 section .text defined public -_isxdigit: 0000f490 section .text defined public -c_lglsh: 0000f778 section .text defined public -_break_while: 00000068 section .bss defined public +_uip_slen: 0000027a section .bss defined public +_uip_conn: 00000337 section .bss defined public +_mqtt_conn: 000000ef section .bss defined public +_code_revision: 00009a30 section .const defined public _stored_debug: 00004062 section .eeprom defined public -_debug: 00000208 section .bss defined public -_uip_conn: 00000392 section .bss defined public -_mqtt_conn: 00000122 section .bss defined public -_htons: 0000f019 section .text defined public -_z_diag: 00000069 section .bss defined public -_parse_POST_address: 0000b6be section .text defined public -_uip_process: 0000e6eb section .text defined public -_update_debug_storage1: 0000d046 section .text defined public -_update_ON_OFF: 0000b4c7 section .text defined public -_debugflash: 0000cfc1 section .text defined public -_mqtt_publish: 0000d205 section .text defined public -_fastflash: 0000cff5 section .text defined public +_debug: 000001ae section .bss defined public +_z_diag: 00000049 section .bss defined public +_ps: 000096db section .const defined public +c_eewrc: 0000f508 section .text defined public +_stored_mqtt_password: 00004040 section .eeprom defined public +_Pending_mqtt_password: 0000009b section .bss defined public +_Invert_word: 00000194 section .bss defined public +_ON_OFF_word: 0000019c section .bss defined public +c_eewrd: 0000f53b section .text defined public +c_ludv: 0000f78d section .text defined public +_int2hex: 0000a79c section .text defined public +c_lglsh: 0000f6f3 section .text defined public +_update_ON_OFF: 0000b954 section .text defined public +_debugflash: 0000cf7e section .text defined public +_mqtt_publish: 0000d1c2 section .text defined public +_fastflash: 0000cfb2 section .text defined public __endzp: 0000000a section .ubsct defined public _magic1: 0000402b section .eeprom defined public _magic3: 0000402d section .eeprom defined public -_parse_POST_MAC: 0000b8d3 section .text defined public -_write_output_pins: 0000cee2 section .text defined public -_read_input_pins: 0000ce25 section .text defined public -_io_map: 00008090 section .const defined public -_encode_16bit_registers: 0000b9bd section .text defined public -_uip_netmask: 000002e1 section .bss defined public -_Pending_netmask: 000001e0 section .bss defined public +_write_output_pins: 0000ce9f section .text defined public +_read_input_pins: 0000cde2 section .text defined public +_io_map: 000080a3 section .const defined public +_encode_16bit_registers: 0000b995 section .text defined public +_uip_netmask: 00000286 section .bss defined public +_Pending_netmask: 00000186 section .bss defined public _stored_netmask: 0000401f section .eeprom defined public -_Enc28j60Send: 0000a33d section .text defined public -_uip_send: 0000f01a section .text defined public -_publish_outbound: 0000c2b4 section .text defined public -___mqtt_send: 0000d3db section .text defined public -_mqtt_mq_find: 0000de63 section .text defined public -_Enc28j60ReadPhy: 0000a0c5 section .text defined public -_Enc28j60WritePhy: 0000a112 section .text defined public -_stpcpy: 0000df85 section .text defined public -_select: 0000a042 section .text defined public -_deselect: 0000a048 section .text defined public -_uip_connect: 0000e60a section .text defined public -_mqtt_connect: 0000d15b section .text defined public -_mqtt_disconnect: 0000d378 section .text defined public -_mqtt_pack_disconnect: 0000da08 section .text defined public -_RXERIF_counter: 00000194 section .bss defined public -_TXERIF_counter: 00000193 section .bss defined public -_TRANSMIT_counter: 0000018f section .bss defined public -_second_counter: 000002b7 section .bss defined public -_MQTT_resp_tout_counter: 000000ed section .bss defined public -_MQTT_not_OK_counter: 000000ec section .bss defined public -_MQTT_broker_dis_counter: 000000eb section .bss defined public -_mqtt_mq_register: 0000dcae section .text defined public -_mqtt_unpack_fixed_header: 0000d6e2 section .text defined public -_mqtt_pack_fixed_header: 0000d79f section .text defined public -_Enc28j60SwitchBank: 0000a0b3 section .text defined public -_SpiReadChunk: 0000e335 section .text defined public -_SpiWriteChunk: 0000e2cc section .text defined public -_mqtt_start_status: 00000127 section .bss defined public -_MQTT_error_status: 000002b6 section .bss defined public -_saved_newlines: 0000006a section .bss defined public +_Enc28j60Send: 0000a3f3 section .text defined public +_uip_send: 0000efba section .text defined public +_publish_outbound: 0000c280 section .text defined public +___mqtt_send: 0000d398 section .text defined public +_mqtt_mq_find: 0000de16 section .text defined public +_Enc28j60ReadPhy: 0000a17b section .text defined public +_Enc28j60WritePhy: 0000a1c8 section .text defined public +_stpcpy: 0000df38 section .text defined public +_select: 0000a0f8 section .text defined public +_deselect: 0000a0fe section .text defined public +_uip_connect: 0000e5ab section .text defined public +_mqtt_connect: 0000d118 section .text defined public +_mqtt_disconnect: 0000d335 section .text defined public +_mqtt_pack_disconnect: 0000d9bb section .text defined public +_RXERIF_counter: 00000096 section .bss defined public +_TXERIF_counter: 00000095 section .bss defined public +_TRANSMIT_counter: 00000091 section .bss defined public +_second_counter: 0000025c section .bss defined public +_MQTT_resp_tout_counter: 00000090 section .bss defined public +_MQTT_not_OK_counter: 0000008f section .bss defined public +_MQTT_broker_dis_counter: 0000008e section .bss defined public +_mqtt_mq_register: 0000dc61 section .text defined public +_mqtt_unpack_fixed_header: 0000d695 section .text defined public +_mqtt_pack_fixed_header: 0000d752 section .text defined public +_Enc28j60SwitchBank: 0000a169 section .text defined public +_SpiReadChunk: 0000e2d6 section .text defined public +_SpiWriteChunk: 0000e26d section .text defined public +_mqtt_start_status: 000000b8 section .bss defined public +_MQTT_error_status: 000000b7 section .bss defined public +_saved_newlines: 00000070 section .bss defined public _stored_config_settings: 00004051 section .eeprom defined public -_Pending_config_settings: 000001c9 section .bss defined public -_check_eeprom_settings: 0000c607 section .text defined public +_Pending_config_settings: 0000016f section .bss defined public +_check_eeprom_settings: 0000c5c4 section .text defined public _stored_uip_ethaddr_oct: 00004017 section .eeprom defined public -_user_reboot_request: 000001a4 section .bss defined public -_Pending_uip_ethaddr_oct: 000001c3 section .bss defined public -_reboot_request: 000001a5 section .bss defined public -_restart_request: 000001a3 section .bss defined public -_state_request: 000001ed section .bss defined public -_mqtt_pack_connection_request: 0000d84e section .text defined public -_mqtt_pack_publish_request: 0000da48 section .text defined public -_mqtt_pack_subscribe_request: 0000dbdd section .text defined public -_mqtt_pack_ping_request: 0000da28 section .text defined public +_user_reboot_request: 0000014a section .bss defined public +_Pending_uip_ethaddr_oct: 00000169 section .bss defined public +_reboot_request: 0000014b section .bss defined public +_restart_request: 00000149 section .bss defined public +_state_request: 00000193 section .bss defined public +_mqtt_pack_connection_request: 0000d801 section .text defined public +_mqtt_pack_publish_request: 0000d9fb section .text defined public +_mqtt_pack_subscribe_request: 0000db90 section .text defined public +_mqtt_pack_ping_request: 0000d9db section .text defined public _CLK_PCKENR1: 000050c7 section absolute defined public absolute _UART2_BRR1: 00005242 section absolute defined public absolute -_clear_saved_postpartial_data: 0000b514 section .text defined public -_uip_appdata: 00000396 section .bss defined public -_uip_sappdata: 000002d7 section .bss defined public +_uip_appdata: 0000033b section .bss defined public +_uip_sappdata: 0000027c section .bss defined public _TIM1_ARRH: 00005262 section absolute defined public absolute _TIM1_CCR2H: 00005267 section absolute defined public absolute _TIM2_ARRH: 0000530d section absolute defined public absolute @@ -218,16 +204,11 @@ _TIM2_CCR2H: 00005311 section absolute defined public absolute _TIM3_ARRH: 0000532b section absolute defined public absolute _TIM3_CCR2H: 0000532f section absolute defined public absolute _DM_BK2RH: 00007f94 section absolute defined public absolute -c_lzmp: 0000f914 section .text defined public -c_smodx: 0000f939 section .text defined public -_FindDevices: 00009ed1 section .text defined public -_check_runtime_changes: 0000c9d4 section .text defined public +c_lzmp: 0000f7bb section .text defined public +c_smodx: 0000f7e0 section .text defined public +_FindDevices: 00009f87 section .text defined public +_check_runtime_changes: 0000c991 section .text defined public c_x: 00000004 section .ubsct defined public zpage -_DS18B20_string: 000000c2 section .bss defined public -_mac_string: 000001a6 section .bss defined public -_parse_POST_string: 0000b53f section .text defined public -_update_mac_string: 0000c99d section .text defined public -___mqtt_ping: 0000d315 section .text defined public _PA_ODR: 00005000 section absolute defined public absolute _PB_ODR: 00005005 section absolute defined public absolute _PC_ODR: 0000500a section absolute defined public absolute @@ -321,7 +302,7 @@ _FLASH_DUKR: 00005064 section absolute defined public absolute _SPI_RXCRCR: 00005206 section absolute defined public absolute _SPI_TXCRCR: 00005207 section absolute defined public absolute _TIM1_RCR: 00005264 section absolute defined public absolute -c_ltor: 0000f7c1 section .text defined public +c_ltor: 0000f77b section .text defined public _RST_SR: 000050b3 section absolute defined public absolute _CLK_CSSR: 000050c8 section absolute defined public absolute _BEEP_CSR: 000050f3 section absolute defined public absolute @@ -333,7 +314,7 @@ _TIM1_SMCR: 00005252 section absolute defined public absolute _TIM4_SR: 00005342 section absolute defined public absolute _ADC_CSR: 00005400 section absolute defined public absolute _SWIM_CSR: 00007f80 section absolute defined public absolute -c_lgor: 0000f786 section .text defined public +c_lgor: 0000f714 section .text defined public _CLK_CMSR: 000050c3 section absolute defined public absolute _CLK_SWCR: 000050c5 section absolute defined public absolute _CLK_SWIMCCR: 000050cd section absolute defined public absolute @@ -345,31 +326,32 @@ _TIM2_PSCR: 0000530c section absolute defined public absolute _TIM3_PSCR: 0000532a section absolute defined public absolute _TIM4_PSCR: 00005345 section absolute defined public absolute _CFG_GCR: 00007f60 section absolute defined public absolute -_ON_OFF_word_new2: 000001f2 section .bss defined public +_ON_OFF_word_new2: 00000198 section .bss defined public _CLK_SWR: 000050c4 section absolute defined public absolute _WWDG_WR: 000050d2 section absolute defined public absolute _TIM1_EGR: 00005257 section absolute defined public absolute _TIM2_EGR: 00005304 section absolute defined public absolute _TIM3_EGR: 00005324 section absolute defined public absolute _TIM4_EGR: 00005343 section absolute defined public absolute -_uip_add32: 0000e4cb section .text defined public +c_lgsub: 0000f741 section .text defined public +_uip_add32: 0000e46c section .text defined public _CLK_CKDIVR: 000050c6 section absolute defined public absolute _CLK_PCKENR2: 000050ca section absolute defined public absolute _UART2_BRR2: 00005243 section absolute defined public absolute _CLK_CCOR: 000050c9 section absolute defined public absolute _magic2: 0000402c section .eeprom defined public -_uip_acc32: 000002ea section .bss defined public +_uip_acc32: 0000028f section .bss defined public _CLK_HSITRIMR: 000050cc section absolute defined public absolute _IWDG_PR: 000050e1 section absolute defined public absolute _SPI_CRCPR: 00005205 section absolute defined public absolute -_uip_hostaddr: 000002e5 section .bss defined public -_uip_draddr: 000002dd section .bss defined public -_uip_mqttserveraddr: 000002d9 section .bss defined public -_Pending_hostaddr: 000001e8 section .bss defined public -_Pending_draddr: 000001e4 section .bss defined public -_Pending_mqttserveraddr: 0000018a section .bss defined public +_uip_hostaddr: 0000028a section .bss defined public +_uip_draddr: 00000282 section .bss defined public +_uip_mqttserveraddr: 0000027e section .bss defined public +_Pending_hostaddr: 0000018e section .bss defined public +_Pending_draddr: 0000018a section .bss defined public +_Pending_mqttserveraddr: 000000b3 section .bss defined public _stored_hostaddr: 00004027 section .eeprom defined public -_IpAddr: 00000199 section .bss defined public +_IpAddr: 0000013f section .bss defined public _stored_draddr: 00004023 section .eeprom defined public _stored_mqttserveraddr: 00004031 section .eeprom defined public _uip_ethaddr: 0000000c section .data defined public @@ -384,8 +366,8 @@ _DM_BK1RL: 00007f92 section absolute defined public absolute _I2C_OARH: 00005214 section absolute defined public absolute _DM_BK1RH: 00007f91 section absolute defined public absolute _lastDiscrep: 0000000a section .data defined public -c_bmulx: 0000f51b section .text defined public -_mqtt_startup: 0000bc23 section .text defined public +_mqtt_startup: 0000bbef section .text defined public +c_bmulx: 0000f4e4 section .text defined public _I2C_SR3: 00005219 section absolute defined public absolute _UART2_CR3: 00005246 section absolute defined public absolute _ADC_CR3: 00005403 section absolute defined public absolute @@ -397,17 +379,19 @@ _I2C_CCRH: 0000521c section absolute defined public absolute _TIM1_PSCRH: 00005260 section absolute defined public absolute _ADC_AWSRH: 0000540c section absolute defined public absolute _ADC_AWCRH: 0000540e section absolute defined public absolute -c_uitolx: 0000f988 section .text defined public -_restart_reboot_step: 000001a2 section .bss defined public -_mqtt_restart_step: 00000121 section .bss defined public -c_lcmp: 0000f731 section .text defined public -c_itolx: 0000f6e7 section .text defined public +c_itolx: 0000f558 section .text defined public +c_uitolx: 0000f84a section .text defined public +_memcmp: 0000f430 section .text defined public +_strcmp: 0000f4c5 section .text defined public +_restart_reboot_step: 00000148 section .bss defined public +_mqtt_restart_step: 000000ee section .bss defined public +c_lcmp: 0000f5a2 section .text defined public _I2C_TRISER: 0000521d section absolute defined public absolute _UART2_CR4: 00005247 section absolute defined public absolute -c_divsl: 0000f7e7 section .text defined public +c_divsl: 0000f5e1 section .text defined public _UART2_CR5: 00005248 section absolute defined public absolute -_auto_pub_toggle: 000000e9 section .bss defined public -_second_toggle: 000002bb section .bss defined public +_auto_pub_toggle: 000000b9 section .bss defined public +_second_toggle: 00000260 section .bss defined public _UART2_CR6: 00005249 section absolute defined public absolute _TIM1_IER: 00005254 section absolute defined public absolute _TIM2_IER: 00005301 section absolute defined public absolute @@ -419,17 +403,17 @@ _TIM2_CCMR1: 00005305 section absolute defined public absolute _TIM2_CCER1: 00005308 section absolute defined public absolute _TIM3_CCMR1: 00005325 section absolute defined public absolute _TIM3_CCER1: 00005327 section absolute defined public absolute -_OctetArray: 000000b6 section .bss defined public +_OctetArray: 00000074 section .bss defined public _TIM1_CCMR2: 00005259 section absolute defined public absolute _TIM1_CCER2: 0000525d section absolute defined public absolute _TIM2_CCMR2: 00005306 section absolute defined public absolute _TIM2_CCER2: 00005309 section absolute defined public absolute _TIM3_CCMR2: 00005326 section absolute defined public absolute -_pBuffer2: 00000226 section .bss defined public +_pBuffer2: 000001cc section .bss defined public _TIM1_CCMR3: 0000525a section absolute defined public absolute _TIM2_CCMR3: 00005307 section absolute defined public absolute _TIM1_CCMR4: 0000525b section absolute defined public absolute -_Port_Mqttd: 0000016d section .bss defined public +_Port_Mqttd: 00000097 section .bss defined public _TIM1_CNTRH: 0000525e section absolute defined public absolute _TIM2_CNTRH: 0000530a section absolute defined public absolute _TIM3_CNTRH: 00005328 section absolute defined public absolute @@ -444,7 +428,7 @@ _ADC_DRL: 00005405 section absolute defined public absolute _ADC_TDRL: 00005407 section absolute defined public absolute _ADC_HTRL: 00005409 section absolute defined public absolute _ADC_LTRL: 0000540b section absolute defined public absolute -_uip_arp_out: 0000f267 section .text defined public +_uip_arp_out: 0000f207 section .text defined public _TIM1_ARRL: 00005263 section absolute defined public absolute _TIM1_CCR2L: 00005268 section absolute defined public absolute _TIM2_ARRL: 0000530e section absolute defined public absolute @@ -458,112 +442,116 @@ _TIM3_CCR1H: 0000532d section absolute defined public absolute _TIM1_CCR1L: 00005266 section absolute defined public absolute _TIM2_CCR1L: 00005310 section absolute defined public absolute _TIM3_CCR1L: 0000532e section absolute defined public absolute -c_imul: 0000f6c6 section .text defined public -c_fmul: 0000f58f section .text defined public -c_okmul: 0000f59d section .text defined public +c_smul: 0000f80b section .text defined public _TIM1_CCR3H: 00005269 section absolute defined public absolute _TIM2_CCR3H: 00005314 section absolute defined public absolute _TIM1_CCR3L: 0000526a section absolute defined public absolute _TIM2_CCR3L: 00005314 section absolute defined public absolute _stored_pin_control: 00004052 section .eeprom defined public -_LEDcontrol: 0000a536 section .text defined public -_pin_control: 000001f8 section .bss defined public -_Pending_pin_control: 000001b3 section .bss defined public +_LEDcontrol: 0000a5ec section .text defined public +_pin_control: 0000019e section .bss defined public +_Pending_pin_control: 00000159 section .bss defined public _TIM1_CCR4H: 0000526b section absolute defined public absolute -c_sdivx: 0000f93f section .text defined public +c_sdivx: 0000f7e6 section .text defined public _TIM1_CCR4L: 0000526c section absolute defined public absolute -_client_id: 00000143 section .bss defined public +_client_id: 0000010f section .bss defined public _TIM1_DTR: 0000526e section absolute defined public absolute _TIM4_ARR: 00005346 section absolute defined public absolute _ITC_SPR1: 00007f70 section absolute defined public absolute -_t100ms_ctr1: 00000195 section .bss defined public -_mqtt_start_ctr1: 00000126 section .bss defined public +_t100ms_ctr1: 0000013b section .bss defined public +_mqtt_start_ctr1: 000000f3 section .bss defined public _ITC_SPR2: 00007f71 section absolute defined public absolute -_mqtt_start_ctr2: 00000125 section .bss defined public +_mqtt_start_ctr2: 000000f2 section .bss defined public _ITC_SPR4: 00007f73 section absolute defined public absolute +c_ladd: 0000f58a section .text defined public _stored_port: 0000401d section .eeprom defined public _stored_mqttport: 0000402f section .eeprom defined public -_parse_POST_port: 0000b7e0 section .text defined public -_Pending_port: 000001de section .bss defined public -_Pending_mqttport: 00000188 section .bss defined public -_mqttport: 0000016f section .bss defined public -c_ladd: 0000f719 section .text defined public -c_lgadd: 0000f761 section .text defined public +_Pending_port: 00000184 section .bss defined public +_Pending_mqttport: 000000b1 section .bss defined public +_mqttport: 00000099 section .bss defined public +c_lgadd: 0000f6dc section .text defined public _ITC_SPR5: 00007f74 section absolute defined public absolute _ITC_SPR6: 00007f75 section absolute defined public absolute _ITC_SPR7: 00007f76 section absolute defined public absolute -c_eewrw: 0000f529 section .text defined public +c_eewrw: 0000f4f2 section .text defined public _ITC_SPR8: 00007f77 section absolute defined public absolute _DM_BK1RE: 00007f90 section absolute defined public absolute _DM_BK2RE: 00007f93 section absolute defined public absolute -_Enc28j60Receive: 0000a28e section .text defined public -_mqtt_keep_alive: 0000016b section .bss defined public -_emb_itoa: 0000a5c6 section .text defined public -_wait_timer: 0000e4a8 section .text defined public -_uip_arp_timer: 0000f061 section .text defined public -_periodic_timer: 000002c2 section .bss defined public -_mqtt_timer: 000002c1 section .bss defined public -_t100ms_timer: 000002bd section .bss defined public -_arp_timer: 000002bf section .bss defined public -_mqtt_outbound_timer: 000002be section .bss defined public +_Enc28j60Receive: 0000a344 section .text defined public +_mqtt_keep_alive: 00000137 section .bss defined public +_emb_itoa: 0000a695 section .text defined public +_wait_timer: 0000e449 section .text defined public +_uip_arp_timer: 0000f001 section .text defined public +_periodic_timer: 00000267 section .bss defined public +_mqtt_timer: 00000266 section .bss defined public +_t100ms_timer: 00000262 section .bss defined public +_arp_timer: 00000264 section .bss defined public +_mqtt_outbound_timer: 00000263 section .bss defined public +c_ldiv: 0000f5c2 section .text defined public +___mqtt_pack_uint16: 0000debc section .text defined public +___mqtt_unpack_uint16: 0000dee0 section .text defined public _numROMs: 00000012 section .bss defined public -_clear_eeprom_debug_bytes: 0000d01b section .text defined public -_First: 00009f17 section .text defined public +_clear_eeprom_debug_bytes: 0000cfd8 section .text defined public +_First: 00009fcd section .text defined public _magic4: 0000402e section .eeprom defined public -_mqtt_enabled: 0000018e section .bss defined public -_reset_pulse: 00009e14 section .text defined public +_mqtt_enabled: 0000013a section .bss defined public +_reset_pulse: 00009eca section .text defined public c_lreg: 00000000 section .ubsct defined public zpage -_Enc28j60ReadReg: 0000a04e section .text defined public -_Enc28j60WriteReg: 0000a06e section .text defined public -_Enc28j60SetMaskReg: 0000a085 section .text defined public -_Enc28j60ClearMaskReg: 0000a09c section .text defined public +_Enc28j60ReadReg: 0000a104 section .text defined public +_Enc28j60WriteReg: 0000a124 section .text defined public +_Enc28j60SetMaskReg: 0000a13b section .text defined public +_Enc28j60ClearMaskReg: 0000a152 section .text defined public _io_reg: 00005000 section absolute defined public absolute -c_lneg: 0000f8e5 section .text defined public -c_lgneg: 0000f8d2 section .text defined public +c_lneg: 0000f766 section .text defined public +c_lgneg: 0000f701 section .text defined public _doneFlag: 0000000b section .data defined public _insertion_flag: 00000044 section .bss defined public -_get_temperature: 00009cba section .text defined public -_send_mqtt_temperature: 000000c1 section .bss defined public -_publish_temperature: 0000c510 section .text defined public -_transmit_byte: 00009e45 section .text defined public +_DS18B20_scratch: 00000080 section .bss defined public +c_lgursh: 0000f758 section .text defined public +_get_temperature: 00009cb8 section .text defined public +_convert_temperature: 00009d71 section .text defined public +_send_mqtt_temperature: 0000007f section .bss defined public +_publish_temperature: 0000c4dc section .text defined public +_transmit_byte: 00009efb section .text defined public _FoundROM: 00000014 section .bss defined public _ROM: 0000003c section .bss defined public -_SpiWriteByte: 0000e2a2 section .text defined public -_SpiReadByte: 0000e30b section .text defined public -_saved_nstate: 000000b5 section .bss defined public -_saved_parsestate: 000000b4 section .bss defined public -_parse_table: 000096a1 section .const defined public -_parse_complete: 000001a0 section .bss defined public -_mqtt_parse_complete: 0000019f section .bss defined public -_upgrade_EEPROM: 0000c5c6 section .text defined public -_timer_update: 0000e41d section .text defined public -_publish_pinstate: 0000c3a1 section .text defined public -_read_bit: 00009e65 section .text defined public -_write_bit: 00009ea2 section .text defined public -_Enc28j60Init: 0000a146 section .text defined public -_gpio_init: 0000a4b3 section .text defined public -_HttpDInit: 0000ab46 section .text defined public -_clock_init: 0000e375 section .text defined public -_spi_init: 0000e27d section .text defined public -_uip_arp_init: 0000f03e section .text defined public -_uip_init: 0000e5db section .text defined public -_mqtt_init: 0000d103 section .text defined public -_strcat: 0000f4fb section .text defined public -_mqtt_mq_init: 0000dc5f section .text defined public -_dallas_crc8: 00009fff section .text defined public -_main: 0000ba1e section .text defined public +_SpiWriteByte: 0000e243 section .text defined public +_SpiReadByte: 0000e2ac section .text defined public +_saved_nstate: 00000073 section .bss defined public +_parse_complete: 00000146 section .bss defined public +_mqtt_parse_complete: 00000145 section .bss defined public +_upgrade_EEPROM: 0000c583 section .text defined public +_timer_update: 0000e3be section .text defined public +_publish_pinstate: 0000c36d section .text defined public +_read_bit: 00009f1b section .text defined public +_write_bit: 00009f58 section .text defined public +_Enc28j60Init: 0000a1fc section .text defined public +_gpio_init: 0000a569 section .text defined public +_HttpDInit: 0000ac66 section .text defined public +_clock_init: 0000e316 section .text defined public +_spi_init: 0000e21e section .text defined public +_uip_arp_init: 0000efde section .text defined public +_uip_init: 0000e57c section .text defined public +_mqtt_init: 0000d0c0 section .text defined public +_strcat: 0000f4b1 section .text defined public +_mqtt_mq_init: 0000dc12 section .text defined public +c_rtol: 0000f7ce section .text defined public +_Port_Httpd: 00000143 section .bss defined public +_saved_nparseleft: 00000071 section .bss defined public +_dallas_crc8: 0000a0b5 section .text defined public +_main: 0000b9f6 section .text defined public __stack: 000007ff section absolute defined public absolute _ITC_SPR3: 00007f72 section absolute defined public absolute -c_lgadc: 0000f751 section .text defined public -_mqtt_sanity_check: 0000c135 section .text defined public -c_ladc: 0000f708 section .text defined public -_publish_callback: 0000c1d4 section .text defined public -_exit: 00009cb8 section .text defined public +c_lgadc: 0000f6cc section .text defined public +_mqtt_sanity_check: 0000c101 section .text defined public +c_ladc: 0000f579 section .text defined public +_publish_callback: 0000c1a0 section .text defined public +_exit: 00009cb6 section .text defined public __vectab: 00008000 section .vector defined public _CLK_ICKR: 000050c0 section absolute defined public absolute _CLK_ECKR: 000050c1 section absolute defined public absolute _IWDG_KR: 000050e0 section absolute defined public absolute -_stack_error: 000001ec section .bss defined public -__stext: 00009cb1 section .text defined public -_Next: 00009f22 section .text defined public -_client_id_text: 00000129 section .bss defined public +_stack_error: 00000192 section .bss defined public +__stext: 00009caf section .text defined public +_Next: 00009fd8 section .text defined public +_client_id_text: 000000f5 section .bss defined public diff --git a/NetworkModule/.Idea_Temp/IDEA.ERR b/NetworkModule/.Idea_Temp/IDEA.ERR index 2660c11..160c05d 100644 --- a/NetworkModule/.Idea_Temp/IDEA.ERR +++ b/NetworkModule/.Idea_Temp/IDEA.ERR @@ -47,37 +47,37 @@ uart.o: uip.o: uip_arp.o: uip_tcpapphub.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)isxdig0.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)memcmp.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)memmov.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strcat0.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strcmp0.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strlen0.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)bmulx.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)eeprom.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)fmul.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ftol.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)imul.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itolx.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itoly.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladc.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladd.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lcmp.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lsdiv.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ldiv.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgadc.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgadd.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lglsh.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgneg.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgor.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsbc.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsub.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgursh.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lneg.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lreg.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ltor.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ludiv.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ldiv.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgneg.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lneg.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lumod.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lzmp.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)rtol.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)sdivx.o: -(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)uitof.o: +(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)smul.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)utolx.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)xreg.o: (C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)yreg.o: diff --git a/NetworkModule/.Idea_Temp/IDEABLD.BAT b/NetworkModule/.Idea_Temp/IDEABLD.BAT index e700607..b210284 100644 --- a/NetworkModule/.Idea_Temp/IDEABLD.BAT +++ b/NetworkModule/.Idea_Temp/IDEABLD.BAT @@ -1,5 +1,5 @@ REM COMMAND FILE BUILT BY IDEA -REM Sun Feb 21 11:31:06 2021 +REM Mon Apr 12 07:55:24 2021 REM cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c" cxstm8 -v -l +strict +debug +modsl0 +split +warn "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "main.c" "mqtt.c" "mqtt_pal.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c" diff --git a/NetworkModule/DS18B20.c b/NetworkModule/DS18B20.c index 407e24d..231c814 100644 --- a/NetworkModule/DS18B20.c +++ b/NetworkModule/DS18B20.c @@ -32,14 +32,17 @@ #include "DS18B20.h" #include "main.h" #include "timer.h" +#include "uart.h" #include "uipopt.h" extern uint8_t DS18B20_scratch_byte[2]; // Array to store scratchpad bytes // read from DS18B20 extern uint8_t OctetArray[11]; // Used in conversion of integer - // values to character values + // values to character values and + // used to store generic strings +// Table used for rounding the decimal part of temperatures static const uint8_t dec_temp[] = { '0', // 0x0000 0.0000 rounded off = 0.0 '1', // 0x0001 0.0625 rounded off = 0.1 @@ -58,7 +61,6 @@ static const uint8_t dec_temp[] = { '9', // 0x1110 0.8750 rounded off = 0.9 '9'}; // 0x1111 0.9375 rounded off = 0.9 - // GLOBAL VARIABLES FOR MAXIM DS18B20 CODE CONTRIBUTION // Derived from Maxim code // https://www.maximintegrated.com/en/design/technical-documents/app-notes/1/162.html @@ -91,14 +93,14 @@ int numROMs; // Count of DS18B20 devices found // voltage on the pull up resistor. //---------------------------------------------------------------------------// -// void get_temperature(uint8_t IO) + void get_temperature() { // This function will be called by main every 30 seconds. The function // reads the current temperature from all devices, then signals the // DS18B20s to start a new conversion so that a new temperature reading // will be ready the next time this function is called. Then the function - // returns leaving the temperature values in the DS18B20_string array. + // returns leaving the temperature values in the DS18B20_scratch array. // // Note that the first time the temperature is read from the DS18B20s the // value will be indeterminate, but on the next read the value will be @@ -130,15 +132,11 @@ void get_temperature() // "nop_cnt<20" yields a 10us delay // The delay is actually about 95% of the calculated value, but this is // close enough for this application. - int i; uint8_t j; uint8_t device_num; - uint8_t DS18B20_scratch_byte[9]; - uint16_t whole_temp; - uint8_t decimal_temp; - extern uint8_t DS18B20_string[5][7]; + extern uint8_t DS18B20_scratch[5][2]; // Read current temperature from up to 5 devices for (device_num = 0; device_num < 5; device_num++) { @@ -184,7 +182,7 @@ void get_temperature() // Send 8 bit read scratchpad command - about 75us per bit // Read 72 bit scratchpad - about 75us per bit // 80 x 75us = 6000us = 6ms - // Approximate time spend in this routine when only the first 2 bytes + // Approximate time spent in this routine when only the first 2 bytes // are read: // Send 8 bit read scratchpad command - about 75us per bit // Read 16 bit scratchpad - about 75us per bit @@ -193,8 +191,8 @@ void get_temperature() for (i=0; i<2; i++) { j = 0x01; while(1) { - if (read_bit() == 1) DS18B20_scratch_byte[i] |= j; - else DS18B20_scratch_byte[i] &= (uint8_t)~j; + if (read_bit() == 1) DS18B20_scratch[device_num][i] |= j; + else DS18B20_scratch[device_num][i] &= (uint8_t)~j; if (j == 0x80) break; j = (uint8_t)(j << 1); } @@ -207,78 +205,237 @@ void get_temperature() // search_ROM process, starting with bit 0 of byte 0. for (i = 0; i < 8; i++) transmit_byte(FoundROM[device_num][i]); transmit_byte(0x44); // convert_temp command - - // Convert temperature reading to string. - // DS18B20_temp_xx is a 16 bit signed value. Bits are organized as - // follows: - // Bits 15,14,13,12,11 are all the sign bit - // Bits 10,9,8,7,6,5,4 are the digits of the temperature whole number - // If positive value these bits can be converted to the decimal - // whole number - // If negative value these bits should be inverted, then converted - // to the decimal whole number and an "-" should be added - // Bits 3,2,1,0 are the decimal part of the temperature - // If positive value and a single decimal is wanted the following - // round off table applies: - // 0x0000 0.0000 rounded off = 0.0 - // 0x0001 0.0625 rounded off = 0.1 - // 0x0010 0.1250 rounded off = 0.1 - // 0x0011 0.1875 rounded off = 0.2 - // 0x0100 0.2500 rounded off = 0.3 - // 0x0101 0.3125 rounded off = 0.3 - // 0x0110 0.3750 rounded off = 0.4 - // 0x0111 0.4375 rounded off = 0.4 - // 0x1000 0.5000 rounded off = 0.5 - // 0x1001 0.5625 rounded off = 0.6 - // 0x1010 0.6250 rounded off = 0.6 - // 0x1011 0.6875 rounded off = 0.7 - // 0x1100 0.7500 rounded off = 0.8 - // 0x1101 0.8125 rounded off = 0.8 - // 0x1110 0.8750 rounded off = 0.9 - // 0x1111 0.9375 rounded off = 0.9 - // If negative the four bits need to be inverted, then 1 added. The - // above table will then apply. - // The decimal part of the conversion is generated with a lookup - // table static const uint8_t dec_temp[] - - whole_temp = DS18B20_scratch_byte[1]; + } + } +} + + +void convert_temperature(uint8_t device_num, uint8_t degCorF) +{ +//---------------------------------------------------------------------------// + // This function will convert a temperature value stored in the + // DS18B20_scratch array into a string in degrees C or degrees F. The + // function leaves the converted result in the global OctetArray string. + // + int16_t whole_temp; + uint8_t decimal_temp; + extern uint8_t DS18B20_scratch[5][2]; + uint8_t temp_string[7]; + + // Convert temperature reading to string. + // DS18B20_temp_xx is a 16 bit signed value. Bits are organized as + // follows: + // Bits 15,14,13,12,11 are all the sign bit + // Bits 10,9,8,7,6,5,4 are the digits of the temperature whole number + // If positive value these bits can be converted to the decimal + // whole number + // If negative value these bits should be inverted, then converted + // to the decimal whole number and an "-" should be added + // Bits 3,2,1,0 are the decimal part of the temperature + // If positive value and a single decimal is wanted the round-off + // table declared in this file applies (static const uint8_t dec_temp[]). + // If negative the four "decimal" bits need to be inverted, then 1 + // added (twos complement). The round-off table then applies. + + // Test tables + // These can be enabled one set at a time to test any code changes made + // to the C and F conversion code. If enabled these test values will + // over-ride any values read from the temperature sensors. +/* + DS18B20_scratch[0][1] = 0x07; // +125.0000C +257.0F + DS18B20_scratch[0][0] = 0xd0; + DS18B20_scratch[1][1] = 0x05; // +85.0000C +185.0F + DS18B20_scratch[1][0] = 0x50; + DS18B20_scratch[2][1] = 0x01; // +25.0625C +77.1F + DS18B20_scratch[2][0] = 0x91; + DS18B20_scratch[3][1] = 0x00; // +10.1250C +50.2F + DS18B20_scratch[3][0] = 0xa2; + DS18B20_scratch[4][1] = 0x00; // +0.5000C +32.9F + DS18B20_scratch[4][0] = 0x08; + + DS18B20_scratch[0][1] = 0x00; // +0.0000C +32.0F + DS18B20_scratch[0][0] = 0x00; + DS18B20_scratch[1][1] = 0xff; // -0.5000C +31.1F + DS18B20_scratch[1][0] = 0xf8; + DS18B20_scratch[2][1] = 0xff; // -10.1250C +13.8F + DS18B20_scratch[2][0] = 0x5e; + DS18B20_scratch[3][1] = 0xfe; // -25.0625C -13.1F + DS18B20_scratch[3][0] = 0x6f; + DS18B20_scratch[4][1] = 0xfc; // -55.0000C -67.0F + DS18B20_scratch[4][0] = 0x90; + + DS18B20_scratch[0][1] = 0x00; // +1.0000C +33.8F + DS18B20_scratch[0][0] = 0x10; + DS18B20_scratch[1][1] = 0x00; // +1.0625C +33.9F + DS18B20_scratch[1][0] = 0x11; + DS18B20_scratch[2][1] = 0x00; // +1.1250C +34.0F + DS18B20_scratch[2][0] = 0x12; + DS18B20_scratch[3][1] = 0x00; // +1.1875C +34.1F + DS18B20_scratch[3][0] = 0x13; + DS18B20_scratch[4][1] = 0x00; // +1.2500C +34.3F + DS18B20_scratch[4][0] = 0x14; + + DS18B20_scratch[0][1] = 0x00; // +1.6875C +35.0F + DS18B20_scratch[0][0] = 0x1b; + DS18B20_scratch[1][1] = 0x00; // +1.7500C +35.2F + DS18B20_scratch[1][0] = 0x1c; + DS18B20_scratch[2][1] = 0x00; // +1.8125C +35.3F + DS18B20_scratch[2][0] = 0x1d; + DS18B20_scratch[3][1] = 0x00; // +1.8750C +35.4F + DS18B20_scratch[3][0] = 0x1e; + DS18B20_scratch[4][1] = 0x00; // +1.9375C +35.5F + DS18B20_scratch[4][0] = 0x1f; + + DS18B20_scratch[0][1] = 0xff; // -1.0000C +30.2F + DS18B20_scratch[0][0] = 0xf0; + DS18B20_scratch[1][1] = 0xff; // -1.0625C +30.1F + DS18B20_scratch[1][0] = 0xef; + DS18B20_scratch[2][1] = 0xff; // -1.1250C +30.0F + DS18B20_scratch[2][0] = 0xee; + DS18B20_scratch[3][1] = 0xff; // -1.1875C +29.9F + DS18B20_scratch[3][0] = 0xed; + DS18B20_scratch[4][1] = 0xff; // -1.2500C +29.8F + DS18B20_scratch[4][0] = 0xec; + + DS18B20_scratch[0][1] = 0xff; // -1.6875C +29.0F + DS18B20_scratch[0][0] = 0xe5; + DS18B20_scratch[1][1] = 0xff; // -1.7500C +28.9F + DS18B20_scratch[1][0] = 0xe4; + DS18B20_scratch[2][1] = 0xff; // -1.8125C +28.7F + DS18B20_scratch[2][0] = 0xe3; + DS18B20_scratch[3][1] = 0xff; // -1.8750C +28.6F + DS18B20_scratch[3][0] = 0xe2; + DS18B20_scratch[4][1] = 0xff; // -1.9375C +28.5F + DS18B20_scratch[4][0] = 0xe1; + + DS18B20_scratch[0][1] = 0xfe; // -17.6875C +00.2F + DS18B20_scratch[0][0] = 0xe5; + DS18B20_scratch[1][1] = 0xfe; // -17.7500C +00.1F + DS18B20_scratch[1][0] = 0xe4; + DS18B20_scratch[2][1] = 0xfe; // -17.8125C -00.1F + DS18B20_scratch[2][0] = 0xe3; + DS18B20_scratch[3][1] = 0xfe; // -17.8750C -00.2F + DS18B20_scratch[3][0] = 0xe2; + DS18B20_scratch[4][1] = 0xfe; // -17.9375C -00.3F + DS18B20_scratch[4][0] = 0xe1; + + DS18B20_scratch[0][1] = 0xfe; // -18.1875C -00.7F + DS18B20_scratch[0][0] = 0xdd; + DS18B20_scratch[1][1] = 0xfe; // -18.2500C -00.9F + DS18B20_scratch[1][0] = 0xdc; + DS18B20_scratch[2][1] = 0xfe; // -18.3125C -01.0F + DS18B20_scratch[2][0] = 0xdb; + DS18B20_scratch[3][1] = 0xfe; // -18.3750C -01.0F + DS18B20_scratch[3][0] = 0xda; + DS18B20_scratch[4][1] = 0xfe; // -18.4375C -01.2F + DS18B20_scratch[4][0] = 0xd9; +*/ + + + if (DS18B20_scratch[device_num][1] != 0x55) { // Check that sensor exists + + if (degCorF == 0) { + // Convert to degrees C + // Extract whole temp and decimal temp parts of the DS18B20 + // values + whole_temp = DS18B20_scratch[device_num][1]; whole_temp = whole_temp << 8; - whole_temp |= DS18B20_scratch_byte[0]; + whole_temp |= DS18B20_scratch[device_num][0]; whole_temp &= 0x07f0; whole_temp = whole_temp >> 4; - - decimal_temp = (uint8_t)DS18B20_scratch_byte[0]; + decimal_temp = (uint8_t)DS18B20_scratch[device_num][0]; decimal_temp &= 0x0f; - - if (DS18B20_scratch_byte[1] & 0xF8) { - // Negative number conversion + + if ((DS18B20_scratch[device_num][1] & 0x80) == 0x80) { + // Negative number conversion. Convert to positive + // number. whole_temp = whole_temp ^ 0x007f; decimal_temp = (uint8_t)(decimal_temp ^ 0x0f); decimal_temp++; decimal_temp = (uint8_t)(decimal_temp & 0x0f); - DS18B20_string[device_num][0] = '-'; + temp_string[0] = '-'; } else { - DS18B20_string[device_num][0] = ' '; + // Positive number + temp_string[0] = ' '; } - - // Build string - emb_itoa(whole_temp, OctetArray, 10, 3); - DS18B20_string[device_num][1] = OctetArray[0]; - DS18B20_string[device_num][2] = OctetArray[1]; - DS18B20_string[device_num][3] = OctetArray[2]; - DS18B20_string[device_num][4] = '.'; - DS18B20_string[device_num][5] = dec_temp[decimal_temp]; - DS18B20_string[device_num][6] = '\0'; } + + + else { + // Convert to degrees F + // This routine avoids the use of float variables to perform + // C to F conversion in order to reduce code size. The result + // is that some conversions are off by 0.1 degree - but this + // is adequate for this application. + { + uint16_t raw_temp; + int16_t F_temp0; + int32_t F_temp1; + int32_t F_temp2; + + // Use the raw number from the DS18B20 including the decimal + raw_temp = DS18B20_scratch[device_num][1]; + raw_temp = raw_temp << 8; + raw_temp |= DS18B20_scratch[device_num][0]; + // Recast raw_temp for subsequent calculations. Why two steps + // here? Recast of a uint16 to a int32 did not work properly, + // but recast of the uint16 to int16, then recast of the int16 + // to the int32 DID work. + F_temp0 = (int16_t)raw_temp; + F_temp1 = (int32_t)F_temp0; + // Add 55 C to the value so math is always positive + // We actually add 55 * 16, or 880, since we are working + // with the raw number which includes 4 bits of decimal + // This next equation also includes the "9" part of the + // "9 / 5" calculation. We use 180 / 100 to avoid loss + // of precision in the integer arithmatic. + F_temp1 = (int32_t)((F_temp1 + 880) * 180); + // It is necessary to separate the "100" part of the + // "180 / 100" arithmatic so the compiler doesn't optimize + // and cause loss of precision. + F_temp2 = F_temp1 / 100; + // Now subtract 1072. This is the combination of the "+32" + // part of the C = (F * 9 / 5) + 32 equation, plus the removal + // of the 55 C offset. Again we are using values mulitplied + // by 16 since we are working with the raw number. + // +32 = 32 * 16 = +512 + // The 55 C offset must be removed in terms of degrees F + // F = (-55 * 9 / 5) * 16 = -1584 + // + 512 - 1584 = -1072 + F_temp2 = F_temp2 - 1072; + // Now divide by 16 to get the "whole number" part of the + // display in degrees F + whole_temp = (int16_t)(F_temp2 / 16); + // Now calculate the "decimal" part of the display in degrees F + decimal_temp = (uint8_t)(F_temp2 & 0xf); + temp_string[0] = ' '; + if (F_temp2 < 0) { + // Must use twos complement if the result is negative + whole_temp = whole_temp * -1; + decimal_temp = (uint8_t)(((decimal_temp ^ 0xf) + 1) & 0x0f); + temp_string[0] = '-'; + } + } + } + + // Build string + emb_itoa(whole_temp, OctetArray, 10, 3); + temp_string[1] = OctetArray[0]; + temp_string[2] = OctetArray[1]; + temp_string[3] = OctetArray[2]; + temp_string[4] = '.'; + temp_string[5] = dec_temp[decimal_temp]; + temp_string[6] = '\0'; + strcpy(OctetArray, temp_string); + } + else { + // Sensor does not exist - return ------ string + strcpy(OctetArray, "------"); } } -// IO 15 is Port G bit 0 (of 0-7) -// PG_DDR 1 is output, 0 is input -// PG_ODR -// PG_IDR // IO 16 is Port C bit 6 (of 0-7) // PC_DDR 1 is output, 0 is input // PC_ODR @@ -294,15 +451,15 @@ int reset_pulse() PC_ODR |= 0x40; // write IO ODR to 1 PC_DDR |= 0x40; // write IO DDR to output PC_ODR &= (uint8_t)~0x40; // write IO ODR to 0 - wait_timer(500); + wait_timer(500); // wait 500us PC_DDR &= (uint8_t)~0x40; // write IO DDR to input - wait_timer(100); + wait_timer(100); // wait 100us // Check for "presence" state on the 1-wire. 0 = device(s) present. rtn = 0; if (PC_IDR & 0x40) rtn = 1; - wait_timer(200); + wait_timer(200); // wait 200us return rtn; } @@ -391,8 +548,6 @@ void write_bit(uint8_t transmit_bit) } - - void FindDevices(void) { // FIND DEVICES diff --git a/NetworkModule/DS18B20.h b/NetworkModule/DS18B20.h index 3f821a3..acc99a4 100644 --- a/NetworkModule/DS18B20.h +++ b/NetworkModule/DS18B20.h @@ -23,6 +23,7 @@ #define __DS18B20_H__ void get_temperature(void); +void convert_temperature(uint8_t device_num, uint8_t degCorF); int reset_pulse(void); uint8_t check_CRC(void); void transmit_byte(uint8_t transmit_value); diff --git a/NetworkModule/Enc28j60.c b/NetworkModule/Enc28j60.c index 68b1023..ff6172b 100644 --- a/NetworkModule/Enc28j60.c +++ b/NetworkModule/Enc28j60.c @@ -54,7 +54,7 @@ #if DEBUG_SUPPORT != 0 // Variables used to store debug information extern uint8_t debug[NUM_DEBUG_BYTES]; -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT extern uint8_t RXERIF_counter; // Counts RXERIF errors extern uint8_t TXERIF_counter; // Counts TXERIF errors diff --git a/NetworkModule/Main.c b/NetworkModule/Main.c index a57ab05..7d8ea39 100644 --- a/NetworkModule/Main.c +++ b/NetworkModule/Main.c @@ -49,7 +49,7 @@ //---------------------------------------------------------------------------// //---------------------------------------------------------------------------// //---------------------------------------------------------------------------// -const char code_revision[] = "20210221 1826"; +const char code_revision[] = "20210412 1333"; //---------------------------------------------------------------------------// //---------------------------------------------------------------------------// //---------------------------------------------------------------------------// @@ -57,11 +57,12 @@ const char code_revision[] = "20210221 1826"; //---------------------------------------------------------------------------// // Stack overflow detection // The following is used to declare two constants at the top of the RAM area. -// Regular variable assignments start at memory address 0x0000 and grow upwards -// to 0x5ff. Stack starts at 0x7ff and grows downward to 0x0600. Two constants -// are placed at 0x5fe and 0x5ff and are monitored to make sure they never -// change. If they do change it implies that the Stack has grown into the -// variable storage RAM. +// Regular variable assignments start at memory address 0x0000 and grow +// upwards to 0x5ff. Stack starts at 0x7ff and grows downward to 0x0600. Two +// constants are placed at 0x5fe and 0x5ff and are monitored to make sure +// they never change. If they do change it implies that the Stack has grown +// into the variable storage RAM, or that a "wild pointer" may have caused +// writes to RAM to exceed the space allocated to RAM. // #pragma section @near [iconst] uint8_t stack_limit1; @@ -137,7 +138,7 @@ uint8_t stack_limit2; // 30 debug bytes // Byte 128 stored_debug[29] // Byte 99 stored_debug[0] -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT // 98 bytes used below // >>> Add new variables HERE <<< @@ -192,7 +193,19 @@ uint8_t stack_limit2; uint8_t *pBuffer2; uint8_t debug[NUM_DEBUG_BYTES]; //---------------------------------------------------------------------------// -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT + +#if MQTT_SUPPORT == 0 +// Define Flash addresses for IO Names and IO Timers +char IO_NAME[16][16] @0xff00; +uint16_t IO_TIMER[16] @0xfec0; +uint16_t Pending_IO_TIMER[16]; + +// Define pin_timers +uint32_t pin_timer[16]; + +#endif // MQTT_SUPPORT + uint8_t pin_control[16]; // Per pin configuration byte @@ -251,29 +264,17 @@ extern uint32_t second_counter; // Time in seconds extern uint8_t OctetArray[11]; // Used in emb_itoa conversions -uint8_t RXERIF_counter; // Counts RXERIF errors detected by the - // ENC28J60 -uint8_t TXERIF_counter; // Counts TXERIF errors detected by the - // ENC28J60 -uint32_t TRANSMIT_counter; // Counts any transmit by the ENC28J60 - - +#if MQTT_SUPPORT == 1 // MQTT variables +// Note: To maintain the same user interface for MQTT compiles and Browser Only +// versions the MQTT user interface variables are always compiled. uint8_t mqtt_enabled; // Used to signal use of MQTT functions - // Initialized to 'disabled', but any - // non-zero MQTT Server IP Adddress will - // cause it to be 'enabled' -uint8_t Pending_mqttserveraddr[4]; // Holds a new user entered MQTT Server - // IP address -uint16_t Pending_mqttport; // Holds a new user entered MQTT Port - // number -char Pending_mqtt_username[11]; // Holds a new user entered MQTT username -char Pending_mqtt_password[11]; // Holds a new user entered MQTT password - + // Initialized to 'disabled'. This can + // only get set to 1 if the MQTT Enable + // bit is set in the Config settings AND + // at least one IO pin is enabled. uint8_t connect_flags; // Used in MQTT setup -uint16_t mqttport; // MQTT port number -uint16_t Port_Mqttd; // In use MQTT port number uint16_t mqtt_keep_alive; // Ping interval struct mqtt_client mqttclient; // Declare pointer to the MQTT client // structure @@ -283,8 +284,6 @@ char client_id_text[26]; // Client ID comprised of text // (12 bytes) and terminator (1 byte) // for a total of 26 bytes. uint8_t mqtt_start; // Tracks the MQTT startup steps -uint8_t mqtt_start_status; // Error (or success) status for startup - // steps uint8_t mqtt_start_ctr1; // Tracks time for the MQTT startup // steps uint8_t mqtt_start_ctr2; // Tracks time for the MQTT startup @@ -304,7 +303,6 @@ struct uip_conn *mqtt_conn; // mqtt_conn points to the connection // have to keep looking it up in the // structure table while setting up MQTT // operations. -extern uint8_t MQTT_error_status; // For MQTT error status display in GUI uint8_t mqtt_restart_step; // Step tracker for restarting MQTT static const unsigned char devicetype[] = "NetworkModule/"; // Used in @@ -316,29 +314,55 @@ unsigned char topic_base[51]; // Used for building connect, subscribe, // NetworkModule/DeviceName123456789/output/+/set // NetworkModule/DeviceName123456789/temp/15 // homeassistant/binary_sensor/macaddressxx/01/config -uint8_t MQTT_resp_tout_counter; // Counts response timeout events in the - // mqtt_sanity_check() function -uint8_t MQTT_not_OK_counter; // Counts MQTT != OK events in the - // mqtt_sanity_check() function -uint8_t MQTT_broker_dis_counter; // Counts broker disconnect events in - // the mqtt_sanity_check() function uint8_t auto_pub_count; // Tracks the Home Assistant Auto Discovery // publish msgs uint8_t auto_pub_toggle; // Tracks the dual message count required for // the Home Assistant Auto Discovery publish msgs +#endif // MQTT_SUPPORT + +// These MQTT variables must always be compiled to maintain a common user +// interface between the MQTT and Browser Only versions. +uint8_t mqtt_start_status; // Error (or success) status for startup + // steps +uint8_t MQTT_error_status; // For MQTT error status display in GUI +uint8_t Pending_mqttserveraddr[4]; // Holds a new user entered MQTT Server + // IP address +uint16_t Pending_mqttport; // Holds a new user entered MQTT Port + // number +char Pending_mqtt_username[11]; // Holds a new user entered MQTT username +char Pending_mqtt_password[11]; // Holds a new user entered MQTT password +uint16_t mqttport; // MQTT port number +uint16_t Port_Mqttd; // In use MQTT port number + + +// The following are diagnostic counters mostly useful for checking for the +// need for Full Duplex in an MQTT setting, they may still be useful in +// other scenarios, so they remain functional even if MQTT is not enabled. +uint8_t RXERIF_counter; // Counts RXERIF errors detected by the + // ENC28J60 +uint8_t TXERIF_counter; // Counts TXERIF errors detected by the + // ENC28J60 +uint32_t TRANSMIT_counter; // Counts any transmit by the ENC28J60 +uint8_t MQTT_resp_tout_counter; // Counts response timeout events in the + // mqtt_sanity_check() function +uint8_t MQTT_not_OK_counter; // Counts MQTT != OK events in the + // mqtt_sanity_check() function +uint8_t MQTT_broker_dis_counter; // Counts broker disconnect events in + // the mqtt_sanity_check() function + // DS18B20 variables -uint32_t check_DS18B20_ctr; // Counter used to trigger temperature - // measurements -uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for the - // DS18B20s -int8_t send_mqtt_temperature; // Indicates if a new temperature measurement - // is pending transmit on MQTT. In this - // application there are 5 sensors, so setting - // to 4 will cause all 5 to transmit (4,3,2,1,0). - // -1 indicates nothing to transmit. -extern int numROMs; // Count of DS18B20 devices found +uint32_t check_DS18B20_ctr; // Counter used to trigger temperature + // measurements +uint8_t DS18B20_scratch[5][2]; // Stores the temperature measurement for the + // DS18B20s +int8_t send_mqtt_temperature; // Indicates if a new temperature measurement + // is pending transmit on MQTT. In this + // application there are 5 sensors, so setting + // to 4 will cause all 5 to transmit (4,3,2,1,0). + // -1 indicates nothing to transmit. +extern int numROMs; // Count of DS18B20 devices found @@ -350,24 +374,23 @@ int main(void) uip_ipaddr_t IpAddr; parse_complete = 0; - mqtt_parse_complete = 0; reboot_request = 0; user_reboot_request = 0; restart_request = 0; t100ms_ctr1 = 0; restart_reboot_step = RESTART_REBOOT_IDLE; - mqtt_close_tcp = 0; stack_error = 0; #if IWDG_ENABLE == 1 init_IWDG(); // Initialize the hardware watchdog -#endif // IWDG_ENABLE == 1 +#endif // IWDG_ENABLE +#if MQTT_SUPPORT == 1 // Initialize MQTT variables + mqtt_parse_complete = 0; + mqtt_close_tcp = 0; mqtt_enabled = 0; // Initialized to 'disabled' mqtt_start = MQTT_START_TCP_CONNECT; // Tracks the MQTT startup steps - mqtt_start_status = MQTT_START_NOT_STARTED; // Tracks error states during - // startup mqtt_keep_alive = 60; // Ping interval in seconds mqtt_start_ctr1 = 0; // Tracks time for the MQTT startup // steps @@ -375,11 +398,27 @@ int main(void) // steps mqtt_sanity_ctr = 0; // Tracks time for the MQTT sanity // steps - MQTT_error_status = 0; // For MQTT error status display in - // GUI mqtt_restart_step = MQTT_RESTART_IDLE; // Step counter for MQTT restart state_request = STATE_REQUEST_IDLE; // Set the state request received to // idle + auto_pub_count = 0; // Initialize Home Assistant Auto + // Discovery message counter + auto_pub_toggle = 0; // Initialize dual msg tracker for + // Home Assistant Auto Discovery + // message counter +#endif // MQTT_SUPPORT + + // The following are only used for tracking MQTT startup status, but they + // must always be compiled in order to maintaing a common user interface + // between the MQTT and Browser only compiles. + mqtt_start_status = MQTT_START_NOT_STARTED; // Tracks error states during + // startup + MQTT_error_status = 0; // For MQTT error status display in + // GUI + + // While the following diagnostic counters are mostly useful for checking for + // the need for Full Duplex in an MQTT setting, they may still be useful in + // other scenarios, so they remain functional even if MQTT is not enabled. TXERIF_counter = 0; // Initialize the TXERIF error counter RXERIF_counter = 0; // Initialize the RXERIF error counter TRANSMIT_counter = 0; // Initialize the TRANSMIT counter @@ -389,11 +428,6 @@ int main(void) // counter MQTT_broker_dis_counter = 0; // Initialize the MQTT broker // disconnect event counter - auto_pub_count = 0; // Initialize Home Assistant Auto - // Discovery message counter - auto_pub_toggle = 0; // Initialize dual msg tracker for - // Home Assistant Auto Discovery - // message counter clock_init(); // Initialize and enable clocks and timers @@ -432,15 +466,9 @@ int main(void) #if DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15 - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // If UART_DEBUG_SUPPORT is enabled the following code forces IO 11 to + // If UART debug support is enabled the following code forces IO 11 to // an output state and keeps it that way. The UART code will operate // the pin for IO 11 as needed for UART transmit to a terminal. - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX pin_control[10] = Pending_pin_control[10] = (uint8_t)0x03; // Set pin 11 to output/enabled // Update the stored_pin_control[] variables unlock_eeprom(); @@ -455,14 +483,15 @@ int main(void) #endif // DEBUG_SUPPORT #if DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15 - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Initialize the UART for debug output InitializeUART(); -#endif // UART_DEBUG_SUPPORT +#endif // DEBUG_SUPPORT - // Initialize DS18B20 temperature storage strings - for (i=0; i<5; i++) strcpy(DS18B20_string[i], "------"); + // Initialize DS18B20 temperature storage values. Scratch byte 1 = 0x55 + // cannot be produced by the DS18B20, so code will recognize this as a + // marker that the temperature has not been read from the DS18B20. + for (i=0; i<5; i++) DS18B20_scratch[i][1] = 0x55; // Initialize DS18B20 devices (if enabled) if (stored_config_settings & 0x08) { // Find all devices @@ -482,17 +511,6 @@ int main(void) stack_limit1 = 0xaa; stack_limit2 = 0x55; -/* - // Initialize mqtt client -UARTPrintf("mqtt_init 1\r\n"); - mqtt_init(&mqttclient, - mqtt_sendbuf, - sizeof(mqtt_sendbuf), - &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN], - UIP_APPDATA_SIZE, - publish_callback); -*/ - #if DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Check RST_SR (Reset Status Register) @@ -526,7 +544,6 @@ UARTPrintf("mqtt_init 1\r\n"); UARTPrintf(OctetArray); UARTPrintf("\r\n"); -// UARTPrintf("Reset Status Register Counters:\r\n"); UARTPrintf("EMCF: "); emb_itoa(debug[25], OctetArray, 10, 3); UARTPrintf(OctetArray); @@ -658,6 +675,7 @@ UARTPrintf("mqtt_init 1\r\n"); } } +#if MQTT_SUPPORT == 1 // Perform MQTT startup if // a) MQTT is enabled // b) Not already at start complete @@ -679,6 +697,7 @@ UARTPrintf("mqtt_init 1\r\n"); && restart_reboot_step == RESTART_REBOOT_IDLE) { mqtt_sanity_check(); } +#endif // MQTT_SUPPORT // Update the time keeping function timer_update(); @@ -715,17 +734,21 @@ UARTPrintf("mqtt_init 1\r\n"); } - // Increment 100ms counters every 100ms + // 100ms timer if (t100ms_timer_expired()) { t100ms_ctr1++; // Increment the 100ms counter. ctr1 is used in the // restart/reboot process. Normally the counter is // not used and will just roll over every 256 // counts. Any code that uses crt1 must reset it to // zero then compare to a value needed for a - // timeout. + // timeout. +#if MQTT_SUPPORT == 0 + decrement_pin_timers(); // Decrement the pin_timers every 100ms +#endif // MQTT_SUPPORT } +#if MQTT_SUPPORT == 1 // If MQTT is enabled and connected check for pin state changes and // publish a message at 50ms intervals. publish_outbound only places the // message in the queue. uip_periodic() will cause the actual @@ -749,6 +772,7 @@ UARTPrintf("mqtt_init 1\r\n"); // used to provide timing for the MQTT Sanity // Check function. } +#endif // MQTT_SUPPORT // Call the ARP timer function every 10 seconds. @@ -763,8 +787,10 @@ UARTPrintf("mqtt_init 1\r\n"); if ((stored_config_settings & 0x08) && (second_counter > (check_DS18B20_ctr + 30))) { check_DS18B20_ctr = second_counter; get_temperature(); +#if MQTT_SUPPORT == 1 send_mqtt_temperature = 4; // Indicates that all 5 temperature sensors - // need to be transmitted. + // need to be transmitted via MQTT. +#endif // MQTT_SUPPORT } @@ -805,7 +831,7 @@ UARTPrintf("mqtt_init 1\r\n"); // The user can press the Reset Button for 10 seconds to restore "factory // defaults". - +#if MQTT_SUPPORT == 1 void mqtt_startup(void) { // This function walks through the steps needed to get MQTT initialized and @@ -914,7 +940,6 @@ void mqtt_startup(void) case MQTT_START_MQTT_INIT: if (mqtt_start_ctr2 > 2) { // Initialize mqtt client -// UARTPrintf("mqtt_init 1\r\n"); mqtt_init(&mqttclient, mqtt_sendbuf, sizeof(mqtt_sendbuf), @@ -998,14 +1023,12 @@ void mqtt_startup(void) if (mqtt_start_ctr1 < 100) { // Allow up to 10 seconds for CONNACK if (connack_received == 1) { -// UARTPrintf("connack received\r\n"); mqtt_start_ctr2 = 0; // Clear 100ms counter mqtt_start_status |= MQTT_START_MQTT_CONNECT_GOOD; mqtt_start = MQTT_START_QUEUE_SUBSCRIBE1; } } else { -// UARTPrintf("restart MQTT_START 1\r\n"); mqtt_start = MQTT_START_TCP_CONNECT; // Clear the error indicator flags mqtt_start_status = MQTT_START_NOT_STARTED; @@ -1054,13 +1077,11 @@ void mqtt_startup(void) if (mqtt_start_ctr1 < 100) { // Allow up to 10 seconds for SUBACK if (suback_received == 1) { -// UARTPrintf("verified SUBSCRIBE1\r\n"); mqtt_start_ctr2 = 0; // Clear 100ms counter mqtt_start = MQTT_START_QUEUE_SUBSCRIBE2; } } else { -// UARTPrintf("restart MQTT_START 2\r\n"); mqtt_start = MQTT_START_TCP_CONNECT; // Clear the error indicator flags mqtt_start_status = MQTT_START_NOT_STARTED; @@ -1093,13 +1114,11 @@ void mqtt_startup(void) if (mqtt_start_ctr1 < 100) { // Allow up to 10 seconds for SUBACK if (suback_received == 1) { -// UARTPrintf("verified SUBSCRIBE2\r\n"); mqtt_start_ctr2 = 0; // Clear 100ms counter if (stored_config_settings & 0x02) { // Home Assistant Auto Discovery enabled mqtt_start = MQTT_START_QUEUE_PUBLISH_AUTO; auto_pub_count = 0; -// UARTPrintf("start HA config\r\n"); } else { mqtt_start = MQTT_START_QUEUE_PUBLISH_ON; @@ -1440,7 +1459,6 @@ void mqtt_startup(void) mqtt_start_ctr2 = 0; if (auto_pub_count == 16) { mqtt_start = MQTT_START_QUEUE_PUBLISH_ON; -// UARTPrintf("end HA config\r\n"); } } } @@ -1593,16 +1611,6 @@ void mqtt_sanity_check(void) break; case MQTT_RESTART_SIGNAL_STARTUP: -/* - // Reinitialize the mqtt client -UARTPrintf("mqtt_init in sanity check\r\n"); - mqtt_init(&mqttclient, - mqtt_sendbuf, - sizeof(mqtt_sendbuf), - &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN], - UIP_APPDATA_SIZE, - publish_callback); -*/ // Set mqtt_restart_step and mqtt_start to re-run the MQTT connection // steps in the main loop mqtt_restart_step = MQTT_RESTART_IDLE; @@ -1694,7 +1702,7 @@ UARTPrintf("mqtt_init in sanity check\r\n"); // IMPORTANT IMPORTANT IMPORTANT // An analysis of the MQTT Startup process shows the CONNECT message to be // up to 120 bytes in length. Add the queue management structure of 11 - // bytes and the mqtt_sendbug needs to be a minimum of 131 bytes. Note that + // bytes and the mqtt_sendbuf needs to be a minimum of 131 bytes. Note that // no PINGREQ can occur during the MQTT Startup process, so the CONNECT // message will occupy the mqtt_sendbuf alone. This sets the required size // of the mqtt_sendbuf at 131 bytes ... will make it 140 to provide a @@ -2127,7 +2135,7 @@ void publish_temperature(uint8_t sensor) topic_base[i] = '\0'; // Build the application message - strcpy(app_message, DS18B20_string[sensor]); + convert_temperature(sensor, 0); // Convert to degress C in OctetArray // Queue publish message mqtt_publish(&mqttclient, @@ -2137,6 +2145,7 @@ void publish_temperature(uint8_t sensor) MQTT_PUBLISH_QOS_0 | MQTT_PUBLISH_RETAIN); } } +#endif // MQTT_SUPPORT void unlock_eeprom(void) @@ -2164,13 +2173,31 @@ void lock_eeprom(void) } +void unlock_flash(void) +{ + // Unlock the Flash + // The Flash must be unlocked to allow any writes to it. + // Note that when Flash is written the hardware will stall code execution + // until the write completes. This typically takes 6ms per write. + FLASH_PUKR = 0x56; // MASS key 1 + FLASH_PUKR = 0xAE; // MASS key 2 +} + + +void lock_flash(void) +{ + // Lock the Flash so that it cannot be written. This clears the PUL bit. + FLASH_IAPSR &= (uint8_t)(~0x02); +} + + void upgrade_EEPROM(void) { // This functions upgrades prior revisions of the EEPROM to the current // revision. int i; - // ----------------------------------------------------------------------// + //-------------------------------------------------------------------------// // Starting with the January 2021 releases the EEPROM will contain a // stored_EEPROM_revision value. // @@ -2191,6 +2218,7 @@ void upgrade_EEPROM(void) // Address, etc) are retained even from the very early releases. Once an // upgrade to a January 2021 (or later) release occurs the EEPROM will // have a revision code that it uses to manage all subsequent upgrades. + //-------------------------------------------------------------------------// // unlock_eeprom(); while ( 1 ) { @@ -2236,14 +2264,18 @@ void upgrade_EEPROM(void) void check_eeprom_settings(void) { int i; + char temp[10]; // Check magic number in EEPROM. - // If no magic number is found it is assumed that the EEPROM has never been - // written, in which case the default Output States, IP Address, Gateway - // Address, Netmask, MAC and Port number will be used. + // // If the magic number IS found then it is assumed that the EEPROM contains // valid copies of the Output States, IP Address, Gateway Address, Netmask, // MAC and Port number. + // + // If no magic number is found it is assumed that the EEPROM has never been + // written, in which case the default Output States, IP Address, Gateway + // Address, Netmask, MAC and Port number will be used. + // // The magic number sequence is MSB 0x55 0xee 0x0f 0xf0 LSB if ((magic4 == 0x55) && @@ -2398,7 +2430,7 @@ void check_eeprom_settings(void) // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // All pins need to default to "input" and "disable" to prevent - // conflicting with external drivers. + // conflicting with external hardware drivers. // pin_control_bytes should be set to defaults // Each pin should be set to 00001010 // 0 ON/OFF @@ -2423,8 +2455,78 @@ void check_eeprom_settings(void) magic1 = 0xf0; // LSB lock_eeprom(); + + +#if MQTT_SUPPORT == 0 + // Initialize Flash memory that is used to store IO Timers + // Since the magic number didn't match all timers are set + // to zero. + unlock_flash(); + // IO_TIMER bytes are written 4 bytes at a time to reduce + // Flash wear + i = 0; + while(i<16) { + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_TIMER[i], 0, 4); + i += 4; + } + + // Initialize Flash memory that is used to store IO Names + // Since the magic number didn't match all names are set + // to defaults. 4 byte writes are used to reduce Flash wear. + // Even though 16 bytes are allocated in Flash, only 8 bytes + // are written here (a 4 byte IO Name and a 4 byte set of + // NULL characters to provide a string terminator). + for (i=0; i<16; i++) { + strcpy(temp, "IO"); + emb_itoa(i+1, OctetArray, 10, 2); + strcat(temp, OctetArray); + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_NAME[i][0], &temp, 4); + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_NAME[i][4], 0, 4); + } + lock_flash(); +#endif // MQTT_SUPPORT + } + + + + +#if MQTT_SUPPORT == 0 + // Check the IO Names in Flash to make sure they are not NULL and + // initialize the pin_timers. + // IO Names might be NULL if the device is programmed using + // "Program/Current Tab" instead of "Program/Address Range". + // "Program/Current Tab" will zero out the Flash area where these + // variables are stored but will leave a valid magic number in + // the EEPROM. If there is already an IO Name stored this code will + // not change it. + unlock_flash(); + for (i=0; i<16; i++) { + strcpy(temp, "IO"); + emb_itoa(i+1, OctetArray, 10, 2); + strcat(temp, OctetArray); + if (IO_NAME[i][0] == 0) { + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_NAME[i][0], &temp, 4); + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_NAME[i][4], 0, 4); + } } + + + lock_flash(); +#endif // MQTT_SUPPORT + + + // Since this code is run one time at boot, initialize the variables that // are dependent on EEPROM content. @@ -2493,6 +2595,7 @@ void check_eeprom_settings(void) // Update the MAC string update_mac_string(); +#if MQTT_SUPPORT == 1 // If the MQTT Enable bit is set in the Config settings AND at least // one IO pin is enabled set the mqtt_enabled byte. if (stored_config_settings & 0x04) { @@ -2500,6 +2603,7 @@ void check_eeprom_settings(void) if (pin_control[i] & 0x01) mqtt_enabled = 1; } } +#endif // MQTT_SUPPORT } @@ -2512,6 +2616,7 @@ void update_mac_string(void) i = 5; j = 0; + while (j<12) { int2hex(stored_uip_ethaddr_oct[i]); mac_string[j++] = OctetArray[0]; @@ -2524,18 +2629,34 @@ void update_mac_string(void) void check_runtime_changes(void) { - // Step 1: Read the input registers and update the pin_control values as - // needed. + //-------------------------------------------------------------------------// + // Step 1: + // Read the input registers and update the pin_control values as needed. // - // Step 2: Check if the user requested changes to Device Name, Output - // States, IP Address, Gateway Address, Netmask, Port, or MAC. If a change - // occurred update the appropriate variables and output controls, and store - // the new values in EEPROM. Note that the value parse_complete is used to - // make sure that a complete POST entry has been received before attempting - // to process the changes made by the user. + // Step 2: + // Check if the UART is enabled via a DEBUG_SUPPORT setting. If yes, + // supersede any settings on IO 11 and force it to an Output for use by the + // UART. + // + // Step 3: + // Check if the DS18B20 feature is enabled. If enabled over-ride the + // pin_control byte settings for IO 16 to force them to all zero. This + // forces the disabled state so the DS18B20 code can utilize the pin for + // temperature sensor communication. + // + // Step 4: + // Manage Output pin Timers. Change Output pin states and Timers as + // appropriate. + // + // Step 5: + // Check if the user requested changes to Device Name, Output States, IP + // Address, Gateway Address, Netmask, Port, or MAC. If a change occurred + // update the appropriate variables and output controls, and store the new + // values in EEPROM. int i; uint8_t update_EEPROM; + uint32_t temp_pin_timer; unlock_eeprom(); @@ -2543,15 +2664,9 @@ void check_runtime_changes(void) #if DEBUG_SUPPORT == 7 || DEBUG_SUPPORT == 15 - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // If UART_DEBUG_SUPPORT is enabled the following code forces IO 11 to - // an output state and keeps it that way. The UART code will operate - // the pin for IO 11 as needed for UART transmit to a terminal. - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + // If UART debug support is enabled the following code forces IO 11 to an + // output state and keeps it that way. The UART code will operate the pin + // for IO 11 as needed for UART transmit to a terminal. pin_control[10] = Pending_pin_control[10] = (uint8_t)0x03; // force to output/enabled // Update the stored_pin_control[] variables if (stored_pin_control[10] != pin_control[10]) stored_pin_control[10] = pin_control[10]; @@ -2573,6 +2688,147 @@ void check_runtime_changes(void) if (stored_pin_control[15] != pin_control[15]) stored_pin_control[15] = pin_control[15]; } +#if MQTT_SUPPORT == 0 + // Manage Output pin Timers. Change Output pin states and Timers as + // appropriate. + // + // Note that Timers are ignored for any pin that is not defined as an + // Output pin. + // + // Check if the user changed the IO_TIMER value while the Timer was + // running: + // If an Output pin IO_TIMER value is changed by the user + // and the pin_timer for that pin is non-zero (the timer is running) + // then set the pin_timer for that pin to the IO_TIMER value + // THEN + // Collect the Pending IO_TIMER values and write them to Flash + // + // Check for Output pin Timer activate: + // If an Output pin and Retain is NOT set + // and pin has a non-zero IO_TIMER + // and the Output pin changed from its idle state to its active state + // then set the pin_timer for that pin to the IO_TIMER + // + // Check for Timer expiration: + // If an Output pin and Retain is NOT set + // and pin has a non-zero IO_TIMER + // and the Output pin is in its active state + // and the pin_timer for that pin is zero + // then set the Output pin to its idle state + // + // Some comments: + // 1) If the user changes the Output pin from active to idle while a + // pin_timer is running nothing needs to be done. One of two things + // happens: + // a) The pin_timer will eventually expire and no pin state change will + // occur. + // b) The user changes the Output pin from idle to active which reloads + // the pin_timer + //-------------------------------------------------------------------------// + + + // Check if the user changed the IO_TIMER value while the pin_timer + // was running. Typically the user is just changing the IO_TIMER value + // to zero, but they may also be correcting a user entry mistake - for + // example the user may have entered 100 minutes when they meant 10 + // minutes, so they fix it in Configuration. The code here is intended + // to allow the user to change the value to any new value, and the + // timer should then continue with that new value. + + // If an Output pin IO_TIMER value is changed by the user + // and the pin_timer for that pin is non-zero (the timer is running) + // then set the pin_timer for that pin to the IO_TIMER value + // THEN + // Collect the Pending IO_TIMER values and write them to Flash + if (parse_complete == 1) { + + for (i=0; i<16; i++) { + if (((pin_control[i] & 0x03) == 0x03) && ((pin_control[i] & 0x04) == 0)) { + if (IO_TIMER[i] != Pending_IO_TIMER[i]) { + pin_timer[i] = calculate_timer(Pending_IO_TIMER[i]); + if (pin_timer[i] == 0x0000) { + if (pin_control[i] & 0x10) { + Pending_pin_control[i] |= 0x80; + pin_control[i] |= 0x80; + } + else { + Pending_pin_control[i] &= 0x7f; + pin_control[i] &= 0x7f; + } + // Update the 16 bit registers with the changed pin states + encode_16bit_registers(); + // Update the Output pins + write_output_pins(); + } + } + } + } + + // Update the IO_TIMER array in Flash from the Pending_IO_TIMER + // array. + unlock_flash(); + + for (i=0; i<8; i+=2) { + // Check for compare 4 bytes at a time. If any miscompare write to + // Flash 4 bytes at a time. + if (IO_TIMER[i] != Pending_IO_TIMER[i] || IO_TIMER[i+1] != Pending_IO_TIMER[i+1]) { + FLASH_CR2 = 0x40; + FLASH_NCR2 = 0xBF; + memcpy(&IO_TIMER[i], &Pending_IO_TIMER[i], 4); + } + } + lock_flash(); + } + + // Check for Output pin Timer activate: + // If an Output pin and Retain is NOT set + // and pin has a non-zero IO_TIMER + // and the Output pin changed from its idle state to its active state + // then set the pin_timer for that pin to the IO_TIMER value + // + for (i=0; i<16; i++) { + if (((pin_control[i] & 0x03) == 0x03) && ((pin_control[i] & 0x04) == 0x00)) { + if ((IO_TIMER[i] & 0x3fff) != 0) { + if ((Pending_pin_control[i] & 0x80) != (pin_control[i] & 0x80)) { + if (((Pending_pin_control[i] & 0x80) == 0x80) && ((pin_control[i] & 0x10) == 0x00)) { + pin_timer[i] = calculate_timer(IO_TIMER[i]); + } + if (((Pending_pin_control[i] & 0x80) == 0x00) && ((pin_control[i] & 0x10) == 0x10)) { + pin_timer[i] = calculate_timer(IO_TIMER[i]); + } + } + } + } + } + + // Check for Timer expiration: + // If an Output pin and Retain is NOT set + /// and pin has a non-zero IO_TIMER + // and the pin_timer for that pin is zero + // and the Output pin is in its active state + // then set the Output pin to its idle state + for (i=0; i<16; i++) { + if (((pin_control[i] & 0x03) == 0x03) && ((pin_control[i] & 0x04) == 0x00)) { + if (((IO_TIMER[i] & 0x3fff) != 0) && (pin_timer[i] == 0)) { + if (((pin_control[i] & 0x80) == 0x80) && ((pin_control[i] & 0x10) == 0x00)) { + Pending_pin_control[i] &= 0x7f; + pin_control[i] &= 0x7f; + } + if (((pin_control[i] & 0x80) == 0x00) && ((pin_control[i] & 0x10) == 0x10)) { + Pending_pin_control[i] |= 0x80; + pin_control[i] |= 0x80; + } + // Update the 16 bit registers with the changed pin states + encode_16bit_registers(); + // Update the Output pins + write_output_pins(); + } + } + } +#endif MQTT_SUPPORT + + + if (parse_complete == 1 || mqtt_parse_complete == 1) { // Check for changes from the user via the GUI, MQTT, or REST commands. // If parse_complete == 1 all TCP Fragments have been received during @@ -2581,7 +2837,7 @@ void check_runtime_changes(void) // received. // Check all pin_control bytes for changes. - // ON/OFF state: If an Output pinÂ’s ON/OFF state changes the EEPROM is + // ON/OFF state: If an Output pin’s ON/OFF state changes the EEPROM is // updated only if Retain is set, but a restart must not occur. // IMPORTANT: This routine must only change Output pin ON/OFF states. // The read_input_pins() function is the only place where Input pin @@ -2647,7 +2903,7 @@ void check_runtime_changes(void) // needed if MQTT is enabled, but it will be done even if MQTT is // not enabled to simplify code. update_EEPROM = 1; - user_reboot_request = 1; + user_reboot_request = 1; } // Check for change in Invert @@ -2658,7 +2914,7 @@ void check_runtime_changes(void) // needed if MQTT is enabled, but it will be done even if MQTT is // not enabled to simplify code. update_EEPROM = 1; - restart_request = 1; + restart_request = 1; } // Check for change in Retain/On/Off bits @@ -2722,6 +2978,19 @@ void check_runtime_changes(void) // Check for changes in the IP Address, Gateway Address, // Netmask, and MQTT Server IP Address. Combined into one // loop for code size reduction. +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// This performa a lot more EEPROM writes than needed. Since 4 bytes are +// always written it would be better to reorganize the EEPROM so that all +// of these values are stored on 4 byte boundaries and, if a write is +// needed, to write a 4 byte word only once instead of writing a byte at +// a time. Changing the method may also be overkill, as these bytes change +// very infrequently, and the EEPROM can be written hundreds of thousands +// of times. +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX for (i=0; i<4; i++) { if (stored_hostaddr[i] != Pending_hostaddr[i]) { // Write the new octet to the EEPROM and singla a restart @@ -2759,11 +3028,13 @@ void check_runtime_changes(void) stored_devicename[i] = Pending_devicename[i]; // No restart is required in non-MQTT applications as this does not // affect Ethernet operation. +#if MQTT_SUPPORT == 1 if (mqtt_enabled == 1) { // If MQTT is enabled a restart is required as this affects the // MQTT topic name. restart_request = 1; } +#endif // MQTT_SUPPORT } } @@ -2896,6 +3167,16 @@ void check_restart_reboot(void) restart_reboot_step = RESTART_REBOOT_ARM2; break; +#if MQTT_SUPPORT == 0 + case RESTART_REBOOT_ARM2: + // Wait 1 second for anything in the process of being transmitted + // to fully buffer. Refresh of a page after POST can take a few + // seconds. + if (t100ms_ctr1 > 9) restart_reboot_step = RESTART_REBOOT_FINISH; + break; +#endif // MQTT_SUPPORT + +#if MQTT_SUPPORT == 1 case RESTART_REBOOT_ARM2: // Wait 1 second for anything in the process of being transmitted // to fully buffer. Refresh of a page after POST can take a few @@ -2910,7 +3191,7 @@ void check_restart_reboot(void) case RESTART_REBOOT_SENDOFFLINE: if (t100ms_ctr1 > 1) { - // We can only get here is mqtt_enabled == 1 + // We can only get here if mqtt_enabled == 1 // Wait at least 100 ms before publishing availability message if (mqtt_start == MQTT_START_COMPLETE) { // Publish the availability "offline" message @@ -2997,6 +3278,7 @@ void check_restart_reboot(void) restart_reboot_step = RESTART_REBOOT_FINISH; } break; +#endif // MQTT_SUPPORT case RESTART_REBOOT_FINISH: if (reboot_request == 1) { @@ -3030,7 +3312,7 @@ void restart(void) // oneflash(); // #else // oneflash(); // Quick flash for normal operation -// #endif DEBUG_SUPPORT != 0 +// #endif DEBUG_SUPPORT LEDcontrol(0); // Turn LED off @@ -3039,12 +3321,15 @@ void restart(void) restart_request = 0; mqtt_close_tcp = 0; +#if MQTT_SUPPORT == 1 mqtt_start = MQTT_START_TCP_CONNECT; mqtt_start_status = MQTT_START_NOT_STARTED; mqtt_start_ctr1 = 0; mqtt_sanity_ctr = 0; MQTT_error_status = 0; mqtt_restart_step = MQTT_RESTART_IDLE; +#endif // MQTT_SUPPORT + state_request = STATE_REQUEST_IDLE; spi_init(); // Initialize the SPI bit bang interface to the @@ -3055,16 +3340,6 @@ void restart(void) uip_init(); // Initialize uIP HttpDInit(); // Initialize httpd; sets up listening ports -/* - // Initialize mqtt client -UARTPrintf("mqtt_init 2\r\n"); - mqtt_init(&mqttclient, - mqtt_sendbuf, - sizeof(mqtt_sendbuf), - &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN], - UIP_APPDATA_SIZE, - publish_callback); -*/ LEDcontrol(1); // Turn LED on // From here we return to the main loop and should start running with new // settings. @@ -3211,6 +3486,37 @@ void write_output_pins(void) } +#if MQTT_SUPPORT == 0 +uint32_t calculate_timer(uint16_t timer_value) +{ + // Calculate the pin_timer value from the IO_TIMER value + // as follows: + // If units = 0.1s pin_timer = IO_TIMER Value + 1 + // If units = 1s pin_timer = IO_TIMER Value * 10 + 1 + // If units = 1m pin_timer = IO_TIMER Value * 10 * 60 + // If units = 1h pin_timer = IO_TIMER Value * 10 * 60 * 60 + // (note for manual: Any setting selected may be up to 100ms + // longer that the selected value) + if ((timer_value & 0xc000) == 0x0000) return (uint32_t)((timer_value & 0x3fff)); + if ((timer_value & 0xc000) == 0x4000) return (uint32_t)(((timer_value & 0x3fff) * 10)); + if ((timer_value & 0xc000) == 0x8000) return (uint32_t)(((timer_value & 0x3fff) * 600)); + if ((timer_value & 0xc000) == 0xc000) return (uint32_t)(((timer_value & 0x3fff) * 36000)); + return 0; +} + + +void decrement_pin_timers(void) +{ + int i; + // This function decrements the pin_timers as needed + // This function is called once per 100ms + for(i=0; i<16; i++) if (pin_timer[i] > 0) pin_timer[i]--; + +// if (pin_timer[0] != 0) UARTPrintf("pin_timer0 is non-zero\r\n"); + +} +#endif MQTT_SUPPORT + void check_reset_button(void) { @@ -3385,7 +3691,7 @@ void update_debug_storage() { // // This loop can be enabled if you want the program to // // hang after capturing data. } -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT #if DEBUG_SUPPORT != 0 @@ -3412,7 +3718,7 @@ void update_debug_storage1() { lock_eeprom(); } -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT #if DEBUG_SUPPORT != 0 @@ -3455,12 +3761,12 @@ void capture_uip_buf_transmit() update_debug_storage(); } } -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT -#if DEBUG_SUPPORT != 0 +#if DEBUG_SUPPORT != 0 && MQTT_SUPPORT == 1 void capture_mqtt_sendbuf() { uint8_t i; @@ -3477,7 +3783,7 @@ void capture_mqtt_sendbuf() update_debug_storage(); // Write to EEPROM } } -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT && MQTT_SUPPORT @@ -3513,4 +3819,4 @@ void capture_uip_buf_receive() update_debug_storage(); } } -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT diff --git a/NetworkModule/httpd.c b/NetworkModule/httpd.c index b69cd4b..5e71f65 100644 --- a/NetworkModule/httpd.c +++ b/NetworkModule/httpd.c @@ -53,21 +53,16 @@ #include "mqtt_pal.h" #include "uipopt.h" #include "uart.h" +#include "ds18b20.h" +#include "iostm8s005.h" // #include "stdlib.h" #include "string.h" #include #define STATE_CONNECTED 0 // Client has just connected -#define STATE_GET_G 1 // G -#define STATE_GET_GE 2 // GE -#define STATE_GET_GET 3 // GET -#define STATE_POST_P 4 // P -#define STATE_POST_PO 5 // PO -#define STATE_POST_POS 6 // POS -#define STATE_POST_POST 7 // POST -#define STATE_GOTGET 8 // Client just sent a GET request -#define STATE_GOTPOST 9 // Client just sent a POST request +#define STATE_GOTGET 1 // Client just sent a GET request +#define STATE_GOTPOST 2 // Client just sent a POST request #define STATE_PARSEPOST 10 // We are currently parsing the // client's POST-data #define STATE_SENDHEADER200 11 // Next we send the HTTP 200 header @@ -98,7 +93,7 @@ extern uint8_t *pBuffer2; extern uint8_t debug[NUM_DEBUG_BYTES]; extern uint8_t stored_debug[NUM_DEBUG_BYTES]; -#endif // DEBUG_SUPPORT != 0 +#endif // DEBUG_SUPPORT extern uint16_t Port_Httpd; // Port number in use @@ -158,80 +153,72 @@ uint8_t saved_nstate; // Saved nState used during TCP Fragment // when a TCP fragmentation boundary occurred: // STATE_NULL - indicates not // processing fragment - // STATE_GET_G - // STATE_GET_GE - // STATE_GET_GET - // STATE_POST_P - // STATE_POST_PO - // STATE_POST_POS - // STATE_POST_POST // STATE_GOTGET // STATE_GOTPOST // STATE_PARSEPOST - parsing POST data -uint8_t saved_parsestate; // Saved ParseState used during TCP Fragment - // recovery. If not STATE_NULL saved_parsestate - // will contain one of the following to - // indicate the ParseState we were in when a - // TCP fragmentation boundary occurred: - // PARSE_CMD - STATE_PARSEPOST, seeking command character (a, b, c etc) - // PARSE_NUM10 - STATE_PARSEPOST, seeking tens digit of command - // PARSE_NUM1 - STATE_PARSEPOST, seeking ones digit of command - // PARSE_EQUAL - STATE_PARSEPOST, seeking equal sign delimiter - // PARSE_VAL - STATE_PARSEPOST, seeking data value following equal sign - // PARSE_DELIM - STATE_PARSEPOST, seeking '&' delimiter -uint8_t saved_nparseleft; // Saved nParseLeft during TCP Fragment recovery -uint8_t saved_postpartial[36]; // If POST packet TCP fragmentation occurs saved_postpartial will - // contain the that part of a POST value that was parsed in - // the previous TCP Fragment as follows: - // saved_postpartial[0] - the parsed ParseCmd - // saved_postpartial[1] - the tens digit of the ParseNum - // saved_postpartial[2] - the ones digit of the ParseNum - // saved_postpartial[3] - the equal sign - // saved_postpartial[4] - the first character of data - // saved_postpartial[5] - the second character of data - // saved_postpartial[x] - more characters of data -uint8_t saved_postpartial_previous[36]; // When TCP Fragments are processed after the first - // packet the saved_postpartial values are copied into the - // saved_postpartial_previous values so that the new parsing - // can use the saved_postpartial space for new data that might - // get interrupted. The saved_postpartial_previous values are - // used to restore the state of parsing from the previous - // TCP Fragment. -uint8_t saved_newlines; // Saved nNewlines value in case TCP fragmentation occurs during - // the /r/n/r/n search. -uint8_t z_diag; // The last value in a POST (hidden), used for diagnostics - -uint8_t break_while; // Used to indicate that a parsing "while loop" break is required -uint8_t alpha[32]; // Used in parsing of multi-character values - -uint8_t current_webpage; // Tracks the web page that is currently displayed +uint16_t saved_nparseleft; // Saved nParseLeft during TCP Fragment + // recovery +uint8_t saved_newlines; // Saved nNewlines value in case TCP + // fragmentation occurs during the /r/n/r/n + // search. +uint8_t parse_tail[38]; // If POST packet TCP fragmentation occurs + // parse_tail will contain partial POST value + // that was at the end of the packet. The + // size of this array is determined by the + // longest POST component. At this time that + // longest component is the &h00 POST reply. +uint8_t z_diag; // The last value in a POST (hidden), used for + // diagnostics +uint8_t break_while; // Used to indicate that a parsing "while loop" + // break is required +uint8_t current_webpage; // Tracks the web page that is currently + // displayed // MQTT variables extern uint8_t mqtt_enabled; // Signals if MQTT has been enabled extern uint8_t stored_mqttserveraddr[4]; // mqttserveraddr stored in EEPROM -extern uint16_t stored_mqttport; // MQTT Port number stored in EEPROM +extern uint16_t stored_mqttport; // MQTT Port number stored in + // EEPROM extern char stored_mqtt_username[11]; // MQTT Username stored in EEPROM extern char stored_mqtt_password[11]; // MQTT Password stored in EEPROM -extern uint8_t Pending_mqttserveraddr[4]; // Temp storage for new MQTT IP Address +extern uint8_t Pending_mqttserveraddr[4]; // Temp storage for new MQTT IP + // Address extern uint16_t Pending_mqttport; // Temp storage for new MQTT Port -extern char Pending_mqtt_username[11]; // Temp storage for new MQTT Username -extern char Pending_mqtt_password[11]; // Temp storage for new MQTT Password - -extern uint8_t mqtt_start_status; // Contains error status from the MQTT start process -extern uint8_t MQTT_error_status; // For MQTT error status display in GUI - -extern uint8_t RXERIF_counter; // Counts RXERIF errors -extern uint8_t TXERIF_counter; // Counts TXERIF errors +extern char Pending_mqtt_username[11]; // Temp storage for new MQTT + // Username +extern char Pending_mqtt_password[11]; // Temp storage for new MQTT + // Password + +extern uint8_t mqtt_start_status; // Contains error status from the + // MQTT start process +extern uint8_t MQTT_error_status; // For MQTT error status display in + // GUI + +extern uint8_t RXERIF_counter; // Counts RXERIF errors +extern uint8_t TXERIF_counter; // Counts TXERIF errors extern uint32_t TRANSMIT_counter; // Counts any transmit -extern uint8_t MQTT_resp_tout_counter; // Counts response timeout events -extern uint8_t MQTT_not_OK_counter; // Counts MQTT != OK events -extern uint8_t MQTT_broker_dis_counter; // Counts broker disconnect events +extern uint8_t MQTT_resp_tout_counter; // Counts response timeout events +extern uint8_t MQTT_not_OK_counter; // Counts MQTT != OK events +extern uint8_t MQTT_broker_dis_counter; // Counts broker disconnect events extern uint32_t second_counter; // Counts seconds since boot // DS18B20 variables -extern uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for the - // DS18B20s +extern uint8_t DS18B20_scratch[5][2]; // Stores the temperature measurement + // for the DS18B20s + +// Variables stored in Flash + +#if MQTT_SUPPORT == 0 +// Define Flash addresses for IO Names and IO Timers +extern char IO_NAME[16][16] @0xff00; +extern uint16_t IO_TIMER[16] @0xfec0; +extern uint16_t Pending_IO_TIMER[16]; +#endif // MQTT_SUPPORT + + + + //---------------------------------------------------------------------------// @@ -245,18 +232,18 @@ extern uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for // code should insert data as the web page constant is copied from flash // memory into the output data buffer. // -// - An example marker is %i01, wherein the CopyHttpData() function in the -// application code will replace the "%i01" characters with a single "0" or +// - An example marker is %n01, wherein the CopyHttpData() function in the +// application code will replace the "%n01" characters with a single "0" or // "1" character to signal the browser to paint a red or green box -// indicating pin status. +// indicating mqtt status. // // - Additional markers are inserted to help with compression of the web page // templates to reduce the amount of flash memory required. In these cases // the markers tell the application code to insert strings that are repeated // many times in the web page HTML text, rather than have them repeatedly -// appear in flash memory. For instance %y00 is used to signal the +// appear in flash memory. For instance %y00 could be used to signal the // application code to insert the string -// "pattern='[0-9]{3}' title='Enter 000 to 255' maxlength='3'>" +// "this is a test string" // While this makes the code harder to read, it makes the web page templates // much smaller. // @@ -280,7 +267,8 @@ extern uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for // // - IMPORTANT: Be sure to carefully update the adjust_template_size function // if any changes are made to the %xxx text replacement markers and strings -// in the templates. +// in the templates. Use CURL to verify that pages sizes are reported +// correctly. // // - The templates include the line // "". @@ -304,7 +292,7 @@ extern uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for //---------------------------------------------------------------------------// - +#if MQTT_SUPPORT == 1 // IO Control Template // // PARSE_BYTES calculation: @@ -335,10 +323,9 @@ extern uint8_t DS18B20_string[5][7]; // Stores the temperature measurement for // + 6 - 1 = 42 #define WEBPAGE_IOCONTROL 0 #define PARSEBYTES_IOCONTROL 42 -#define PARSEBYTES_IOCONTROL_ADDL 0 static const char g_HtmlPageIOControl[] = "%y04%y05" - "IO Control" + "%a00: IO Control" "" "" "

IO Control

" @@ -349,19 +336,19 @@ static const char g_HtmlPageIOControl[] = "%a00" "" " lines. // 4) Add double quotes at the start and end of the minfied script to make it part of the // constant string. @@ -504,10 +491,9 @@ const m = (data => { // the sum of the two must not exceed 482. #define WEBPAGE_CONFIGURATION 1 #define PARSEBYTES_CONFIGURATION 194 -#define PARSEBYTES_CONFIGURATION_ADDL 0 static const char g_HtmlPageConfiguration[] = "%y04%y05" - "Configuration" + "%a00: Configuration" "" "" "

Configuration

" @@ -586,32 +572,33 @@ static const char g_HtmlPageConfiguration[] = "Boot state" "" " lines. // 4) Add double quotes at the start and end of the minfied script to make it part of the // constant string. @@ -639,9 +626,9 @@ static const char g_HtmlPageConfiguration[] = const m = (data => { const ip_input_names = ['b00', 'b04', 'b08', 'b12'], port_input_names = ['c00', 'c01'], - features = { "Full Duplex": 1, "HA Auto": 6, "MQTT": 4, "DS18B20": 8 }, - pin_types = { "disabled": 0, "input": 1, "output": 3 }, - boot_state = { "retain": 8, "on": 16, "off": 0 }, + features = { 'Full Duplex': 1, 'HA Auto': 6, 'MQTT': 4, 'DS18B20': 8 }, + pin_types = { 'disabled': 0, 'input': 1, 'output': 3 }, + boot_state = { 'retain': 8, 'on': 16, 'off': 0 }, doc=document, loc=location, selector=doc.querySelector.bind(doc), @@ -658,7 +645,7 @@ const m = (data => { selector_apply_fn = (query, fn) => { for (const e of doc.querySelectorAll(query)) { fn(e) } }, set_attributes = (e, d) => { for (const [k, v] of get_entries(d)) { e.setAttribute(k, v); } }, make_options = (o, v) => get_entries(o).map((o) => ``).join(''), - make_checkbox = (name, bit, value, title='') => `${title}`, + make_checkbox = (name, bit, value, title='') => `${title}`, get_form_data = () => { const form_data = new FormData(form), collect_bits = (name) => form_data.getAll(name).map(v => parse_int(v)).reduce((a, b) => a | b, 0); @@ -685,24 +672,24 @@ const m = (data => { }, reload_page = () => loc.reload(), wait_reboot = () => { - doc.body.innerText = "Wait 5s..."; + doc.body.innerText = 'Wait 5s...'; setTimeout(reload_page, 5000); }, reboot = () => { - send_request("GET", "/91"); + send_request('GET', '/91'); wait_reboot(); }, submitForm = (event) => { event.preventDefault(); - const string_data = Array.from(get_form_data().entries(), ([k, v]) => `${encode(k)}=${encode(v)}`).join("&"); - send_request("POST", "/", string_data + '&z00=0'); + const string_data = Array.from(get_form_data().entries(), ([k, v]) => `${encode(k)}=${encode(v)}`).join('&'); + send_request('POST', '/', string_data + '&z00=0'); wait_reboot(); }, features_data = convert_from_hex(data.g00)[0], common_attributes = {required: true}; - selector_apply_fn('.ip', (e) => { set_attributes(e, {...common_attributes, title: 'Enter valid', pattern: '((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])([.](?!$)|$)){4}' }); }); - selector_apply_fn('.port', (e) => { set_attributes(e, {...common_attributes, title: 'Enter 10 to 65535', pattern: '[0-9]{2,5}', maxlength: 5 }); }); + selector_apply_fn('.ip', (e) => { set_attributes(e, {...common_attributes, title: 'x.x.x.x format', pattern: '((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])([.](?!$)|$)){4}' }); }); + selector_apply_fn('.port', (e) => { set_attributes(e, {...common_attributes, type: 'number', min: 10, max: 65535 }); }); selector_apply_fn('.up input', (e) => { set_attributes(e, {title: '0 to 10 letters, numbers, and -_*. no spaces. Blank for no entry.', maxlength: 10, pattern: '[0-9a-zA-Z-_*.]{0,10}$' }); }); ip_input_names.forEach((n) => set_input_value(n, convert_from_hex(data[n]).join('.'))); @@ -716,9 +703,9 @@ const m = (data => { document_write(`#${i + 1}${checkbox}${make_select}${debug_column}`); }); - selector(".f").innerHTML = Array.from( + selector('.f').innerHTML = Array.from( get_entries(features), - ([name, bit]) => make_checkbox('g00', bit, features_data, name)).join("
" + ([name, bit]) => make_checkbox('g00', bit, features_data, name)).join('
' ); @@ -736,282 +723,686 @@ const m = (data => { }); */ +#endif // MQTT_SUPPORT -// .........1.........2.........3.........4.........5.........6.........7.........8.........9.........0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0.........1.........2.........3.........4.........5.........6 - - -#if UIP_STATISTICS == 1 -// Statistics page Template -#define WEBPAGE_STATS 5 -static const char g_HtmlPageStats[] = -// "" -// "" - "" - "" - "Network Statistics" - "" - "" - "" - "" - "" - "

Network Statistics

" - "

Values shown are since last power on or reset

" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "
%e00Dropped packets at the IP layer
%e01Received packets at the IP layer
%e02Sent packets at the IP layer
%e03Packets dropped due to wrong IP version or header length
%e04Packets dropped due to wrong IP length, high byte
%e05Packets dropped due to wrong IP length, low byte
%e06Packets dropped since they were IP fragments
%e07Packets dropped due to IP checksum errors
%e08Packets dropped since they were not ICMP or TCP
%e09Dropped ICMP packets
%e10Received ICMP packets
%e11Sent ICMP packets
%e12ICMP packets with a wrong type
%e13Dropped TCP segments
%e14Received TCP segments
%e15Sent TCP segments
%e16TCP segments with a bad checksum
%e17TCP segments with a bad ACK number
%e18Received TCP RST (reset) segments
%e19Retransmitted TCP segments
%e20Dropped SYNs due to too few connections avaliable
%e21SYNs for closed ports, triggering a RST
" - "%y03/61' method='GET'>" - "%y03/66' method='GET'>" - "%y03/67' method='GET'>" - "" - ""; -#endif // UIP_STATISTICS == 1 +//---------------------------------------------------------------------------// -#if DEBUG_SUPPORT == 11 || DEBUG_SUPPORT == 15 -// Link Error Statistics page Template -#define WEBPAGE_STATS 5 -static const char g_HtmlPageStats[] = - "%y04%y05" - "" - "" - "" - "" - "" - "" - "" - "
31 %e31
32 %e32
33 %e33
35 %e35
" - "" - "" - "" - "" - ""; -#endif // UIP_STATISTICS +#if MQTT_SUPPORT == 0 +// IO Control Template +// +// PARSE_BYTES calculation: +// The form contained in this webpage will generate several data update +// replies. These replies need to be parsed to extract the data from them. We +// need to stop parsing the reply POST data after all update bytes are parsed. +// The formula for determining the stop value is as follows: +// Each POST has a "wrapper" consisting of +// 1 byte ParseCmd +// 2 byte ParseNum +// 1 byte egual sign +// 1 byte Delimiter +// So, add 5 bytes to each POST as defined here: +// +// For 1 of the replies (Pin Control): +// POST consists of 32 bytes data plus 5 byte wrapper (37 bytes) +// PLUS +// For 1 of the replies (hidden): +// example: z00=x where x is 1 byte (note no &) +// POST consists of a 1 byte data plus 4 byte wrapper (5 bytes) +// THUS +// The formula in this case is +// PARSEBYTES = (1 x 37) +// + (1 x 5) +// PARSEBYTES = 37 +// + 5 = 42 +#define WEBPAGE_IOCONTROL 0 +#define PARSEBYTES_IOCONTROL 42 +static const char g_HtmlPageIOControl[] = +"%y04%y05" + "%a00: IO Control" + "" + "" + "

IO Control

" + "
" + "" + "" + "" + "" + "" + "" - "
Name:%a00
" - "

" - " " - "

"; -static const uint8_t page_string01_len = sizeof(page_string01) - 1; -static const uint8_t page_string01_len_less4 = sizeof(page_string01) - 5; -// STRING LENGTH MUST BE LESS THAN 256 -#if (page_string01_len > 255) - #error "page_string01 is too big" -#endif - +// Credit to Jevdeni Kiski for the javascript work and html improvements. +// Below is the raw script used above before minify. +// 1) Copy raw script to minify website, for example https://javascript-minifier.com/ +// 2) Copy the resulting minified script to an editor and replace all double quotes with +// single quotes. THIS STEP IS VERY IMPORTANT. +// 3) Copy the result to the above between the lines. +// 4) Add double quotes at the start and end of the minfied script to make it part of the +// constant string. +// 5) It is OK to break up the minified script into lines enclosed by double quotes (just +// to make it all visible in the code editors). But make sure no spaces are inadvertantly +// removed from the minified script. -// String for %y02 replacement in web page templates -static const char page_string02[] = - " " - " " \ - "" - -// String for %y02 replacement in web page templates -#define s3 "" \ - " " \ - "" + "" + "" + "" + ""; +#endif // UIP_STATISTICS + + + +#if DEBUG_SUPPORT == 11 || DEBUG_SUPPORT == 15 +// Link Error Statistics page Template +#define WEBPAGE_STATS2 6 +static const char g_HtmlPageStats2[] = + "%y04%y05" + "%a00: Link Error Statistics" + "" + "" + "

Link Error Statistics

" + "" + "" + "" + "" + "" + "
31 %e31
32 %e32
33 %e33
35 %e35
" + "
" + "" + "" + "" + "" + ""; +#endif // DEBUG_SUPPORT + + +// Very Short IO state page Template +// Only responds with a TCP payload that contains the 16 alphanumeric +// characters representing the IO pins states. The response is not +// browser compatible. +// 4 bytes; size of reports 5 +#define WEBPAGE_SSTATE 7 +static const char g_HtmlPageSstate[] = + "%f00"; + + +//---------------------------------------------------------------------------// +// The following creates an array of strings that are commonly used strings +// in the HTML pages. To reduce the size of the HTML pages these common +// strings are replaced with placeholders of the form "%yxx", then when the +// HTML page is copied to the trasnmit buffer the placeholders are replaced +// with one of the strings in this array. The length of each string is +// manually counted and put in the associated _len value. When the _len value +// is needed it often has 4 subtracted (as the strings are replacing the 4 +// character placeholder), so that subtraction is done once here. + +// The following creates an array of 6 strings of variable length + +// String for %y00 replacement in web page templates +#define s0 "" \ + "placeholder" + +// String for %y01 replacement in web page templates +#define s1 "" \ + "" \ + "" \ + "

" \ + " " \ + "" + +// String for %y02 replacement in web page templates +#define s2 "" \ + " " \ + "