Add push event (P13/PD.5 toggle every 10 sec && send state P13 to BLYNK
server)
This commit is contained in:
@@ -693,11 +693,13 @@ uint32_t millis(void)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
// Time count function; this function have to call by timer (1ms)
|
// Time count function; this function have to call by timer (1ms)
|
||||||
void blynk_time_handler(void)
|
void blynk_time_handler(void)
|
||||||
{
|
{
|
||||||
blynk_time_1ms++;
|
blynk_time_1ms++;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Custom delay for checking timeout count
|
// Custom delay for checking timeout count
|
||||||
uint8_t blynk_custom_delay(uint32_t delayms)
|
uint8_t blynk_custom_delay(uint32_t delayms)
|
||||||
@@ -771,3 +773,14 @@ void blynk_syncAll(void)
|
|||||||
{
|
{
|
||||||
sendCmd(BLYNK_CMD_HARDWARE_SYNC, 0, NULL, 0, NULL, 0);
|
sendCmd(BLYNK_CMD_HARDWARE_SYNC, 0, NULL, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void blynk_push_pin(uint8_t pin)
|
||||||
|
{
|
||||||
|
uint8_t rsp_mem[16];
|
||||||
|
uint16_t rsp_len;
|
||||||
|
memset(rsp_mem, 0, sizeof(rsp_mem));
|
||||||
|
rsp_len = SPRINTF((char *)rsp_mem, "dw %d %d", pin, digitalRead(pin));
|
||||||
|
replacetonull(rsp_mem, ' ');
|
||||||
|
sendCmd(BLYNK_CMD_HARDWARE, 0, rsp_mem, rsp_len, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,5 +141,7 @@ void blynk_run(void);
|
|||||||
uint8_t is_blynk_connection_available(void);
|
uint8_t is_blynk_connection_available(void);
|
||||||
void sendCmd(uint8_t cmd, uint16_t id, uint8_t * data, size_t length, uint8_t * data2, size_t length2);
|
void sendCmd(uint8_t cmd, uint16_t id, uint8_t * data, size_t length, uint8_t * data2, size_t length2);
|
||||||
void blynk_syncAll(void);
|
void blynk_syncAll(void);
|
||||||
|
void blynk_push_pin(uint8_t pin);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ uint8_t digitalRead(uint8_t pin)
|
|||||||
val = sw1_read()?0:!0;
|
val = sw1_read()?0:!0;
|
||||||
PRINTF("SW1 is: %d %s\r\n", val, val?"HIGH":"LOW");
|
PRINTF("SW1 is: %d %s\r\n", val, val?"HIGH":"LOW");
|
||||||
}
|
}
|
||||||
|
else if(pin == 13)
|
||||||
|
{
|
||||||
|
val = led2_read()?1:0;
|
||||||
|
PRINTF("LED2 is: %d %s\r\n", val, val?"HIGH":"LOW");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
val = 1;
|
val = 1;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Ethernet/socket.h"
|
#include "Ethernet/socket.h"
|
||||||
#include "Ethernet/wizchip_conf.h"
|
#include "Ethernet/wizchip_conf.h"
|
||||||
|
|
||||||
|
//Shouldn't use here
|
||||||
//******************************* Fat FS declare related: BEGIN
|
//******************************* Fat FS declare related: BEGIN
|
||||||
/*
|
/*
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
@@ -44,13 +45,20 @@ extern unsigned long millis(void);
|
|||||||
extern int freeRam (void);
|
extern int freeRam (void);
|
||||||
|
|
||||||
//M644P/M1284p Users LEDS:
|
//M644P/M1284p Users LEDS:
|
||||||
//LED1/PORTC.4- m644p/m1284p maxxir
|
//LED1/PORTC.4/20 - m644p/m1284p maxxir brd
|
||||||
#define led1_conf() DDRC |= (1<<DDC4)
|
#define led1_conf() DDRC |= (1<<DDC4)
|
||||||
#define led1_high() PORTC |= (1<<PORTC4)
|
#define led1_high() PORTC |= (1<<PORTC4)
|
||||||
#define led1_low() PORTC &= ~(1<<PORTC4)
|
#define led1_low() PORTC &= ~(1<<PORTC4)
|
||||||
#define led1_tgl() PORTC ^= (1<<PORTC4)
|
#define led1_tgl() PORTC ^= (1<<PORTC4)
|
||||||
#define led1_read() (PORTC & (1<<PORTC4))
|
#define led1_read() (PORTC & (1<<PORTC4))
|
||||||
|
|
||||||
|
//LED2/PORTD.5/13 - m644p/m1284p maxxir brd
|
||||||
|
#define led2_conf() DDRD |= (1<<DDD5)
|
||||||
|
#define led2_high() PORTD |= (1<<PORTD5)
|
||||||
|
#define led2_low() PORTD &= ~(1<<PORTD5)
|
||||||
|
#define led2_tgl() PORTD ^= (1<<PORTD5)
|
||||||
|
#define led2_read() (PORTD & (1<<PORTD5))
|
||||||
|
|
||||||
#define sw1_conf() {DDRC &= ~(1<<DDC5); PORTC |= (1<<PORTC5);}
|
#define sw1_conf() {DDRC &= ~(1<<DDC5); PORTC |= (1<<PORTC5);}
|
||||||
#define sw1_read() (PINC & (1<<PINC5))
|
#define sw1_read() (PINC & (1<<PINC5))
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ uint8_t Domain_IP[4] = {0, }; // Translated IP address by DNS S
|
|||||||
* OK (v1.4)Analog Read/Write
|
* OK (v1.4)Analog Read/Write
|
||||||
* OK (v1.5)Restore pins state on board reboot
|
* OK (v1.5)Restore pins state on board reboot
|
||||||
* OK ??3.Try fix frequent reconnection with blynk server - every ~22sec may be this OK.
|
* OK ??3.Try fix frequent reconnection with blynk server - every ~22sec may be this OK.
|
||||||
|
* OK (v1.6) Add push event (P13/PD.5 toggle every 10 sec && send state P13 to BLYNK server)
|
||||||
* Need compare local blynk.c code with modern <blynk> library - (Too old version here - 0.2.1 (On git blynk March 2019 - 0.6.x) )
|
* Need compare local blynk.c code with modern <blynk> library - (Too old version here - 0.2.1 (On git blynk March 2019 - 0.6.x) )
|
||||||
*
|
*
|
||||||
* (3) Trying WIZNET5500 init with using official Wiznet ioLibrary_Driver
|
* (3) Trying WIZNET5500 init with using official Wiznet ioLibrary_Driver
|
||||||
@@ -100,7 +101,7 @@ volatile unsigned long _millis; // for millis tick !! Overflow every ~49.7 days
|
|||||||
//*********Program metrics
|
//*********Program metrics
|
||||||
const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции
|
const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции
|
||||||
const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции
|
const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции
|
||||||
const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.5 Static IP BLYNK WIZNET_5500 ETHERNET 14/03/2019\r\n"; // Program name
|
const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.6 Static IP BLYNK WIZNET_5500 ETHERNET 14/03/2019\r\n"; // Program name
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128__)
|
#if defined(__AVR_ATmega128__)
|
||||||
const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128
|
const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128
|
||||||
@@ -382,42 +383,12 @@ void IO_LIBRARY_Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//***************** WIZCHIP INIT: END
|
//***************** WIZCHIP INIT: END
|
||||||
/*
|
|
||||||
void spi_speed_tst(void)
|
|
||||||
{
|
|
||||||
// Here on SPI pins: MOSI 400Khz freq out, on SCLK 3.2MhzOUT
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
SPI_WRITE(0xF0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//uint8_t prev_sw1 = 1; // VAR for sw1 pressing detect
|
|
||||||
|
|
||||||
// INIT MCU
|
// INIT MCU
|
||||||
avr_init();
|
avr_init();
|
||||||
spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5)
|
spi_init(); //SPI Master, MODE0, 4Mhz(DIV4), CS_PB.3=HIGH - suitable for WIZNET 5x00(1/2/5)
|
||||||
//spi_speed_tst(); / Here on SPI pins: MOSI 400Khz freq out, on SCLK 3.2MhzOUT (Witk SPI CLK 4Mhz)
|
|
||||||
|
|
||||||
|
|
||||||
// Print program metrics
|
// Print program metrics
|
||||||
@@ -499,6 +470,7 @@ int main()
|
|||||||
// Test for Ethernet data transfer validation
|
// Test for Ethernet data transfer validation
|
||||||
uint32_t timer_tick_1sec = millis();
|
uint32_t timer_tick_1sec = millis();
|
||||||
uint8_t blynk_restore_connection = 1;
|
uint8_t blynk_restore_connection = 1;
|
||||||
|
uint8_t timer_led2_push_10sec = 0;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
//Here at least every 1sec
|
//Here at least every 1sec
|
||||||
@@ -506,17 +478,7 @@ int main()
|
|||||||
// Blynk process handler
|
// Blynk process handler
|
||||||
blynk_run();
|
blynk_run();
|
||||||
|
|
||||||
//Use Hercules Terminal to check loopback tcp:5000 and udp:3000
|
//Here every 1sec event
|
||||||
/*
|
|
||||||
* https://www.hw-group.com/software/hercules-setup-utility
|
|
||||||
* */
|
|
||||||
//loopback_tcps(SOCK_TCPS,ethBuf0,PORT_TCPS);
|
|
||||||
//loopback_udps(SOCK_UDPS,ethBuf0,PORT_UDPS);
|
|
||||||
|
|
||||||
//loopback_ret = loopback_tcpc(SOCK_TCPS, gDATABUF, destip, destport);
|
|
||||||
//if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code
|
|
||||||
|
|
||||||
//Here every 1sec
|
|
||||||
if((millis()-timer_tick_1sec)> 1000)
|
if((millis()-timer_tick_1sec)> 1000)
|
||||||
{
|
{
|
||||||
//here every 1 sec
|
//here every 1 sec
|
||||||
@@ -532,6 +494,14 @@ int main()
|
|||||||
blynk_syncAll();
|
blynk_syncAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Every 10sec event for LED2 PIN13
|
||||||
|
if(++timer_led2_push_10sec == 10)
|
||||||
|
{
|
||||||
|
timer_led2_push_10sec = 0; //Clear timer_led2..
|
||||||
|
//Every 10sec toggle, and push LED2 PIN13/PD5 state to BLYNK server
|
||||||
|
led2_tgl();
|
||||||
|
blynk_push_pin(13);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -589,6 +559,9 @@ static void avr_init(void)
|
|||||||
led1_conf();
|
led1_conf();
|
||||||
led1_low();// LED1 is OFF
|
led1_low();// LED1 is OFF
|
||||||
|
|
||||||
|
led2_conf();
|
||||||
|
led2_low();//LED2 is OFF
|
||||||
|
|
||||||
|
|
||||||
sw1_conf();//SW1 internal pull-up
|
sw1_conf();//SW1 internal pull-up
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user