Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Connect to WIFI
- AT+CWJAP="MYNET","MYPASSWORD"rn
- /*
- * Loop
- *
- * Open TCP connection
- * Send 10 bytes
- * Close TCP Connection
- */
- AT+CIPSTART="TCP","104.111.111.111",667rn
- AT+CIPSEND=10rn1111122222rn
- AT+CIPCLOSErn
- Ncat: Connection from 111.111.111.111:11672.
- 1111122222
- Ncat: Connection from 111.111.111.111:35756.
- 2AT+CIPCLO1111122222
- Ncat: Connection from 111.111.111.111:8784.
- 1111122222
- Ncat: Connection from 111.111.111.111:63288.
- 1111122222
- Ncat: Connection from 111.111.111.111:28498.
- 1111122222
- Ncat: Connection from 111.111.111.111:33319.
- 1111122222
- Ncat: Connection from 111.111.111.111:35146.
- 1111122222
- Ncat: Connection from 111.111.111.111:34454.
- 1111122222
- Ncat: Connection from 111.111.111.111:33916.
- 1111122222
- Ncat: Connection from 111.111.111.111:37095.
- 1111122222
- Ncat: Connection from 111.111.111.111:12652.
- 1111122222
- Ncat: Connection from 111.111.111.111:61951.
- 1111122222
- Ncat: Connection from 111.111.111.111:27051.
- 1111122222
- Ncat: Connection from 111.111.111.111:61870.
- 111122222A1111122222
- Ncat: Connection from 111.111.111.111:38063.
- 1111122222
- Ncat: Connection from 111.111.111.111:32270.
- 111122222A1111122222
- 2AT+CIPCLO1111122222
- 1. The data I receive from ESP8266 is for the most part 0x00, so I can't read and process the responses.
- 2. Not totally sure if this is correct: UBRR0 = ((( F_CPU / (BAUD * 16UL ))) - 1);
- In the original example, it had 'BAUD * 8', but it didn't work for me, when changing it to 16, esp8266 started to understand commands.
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #define F_CPU 8000000UL
- #define BAUD 9600
- char buffer[ 70 ];
- int received = 0;
- void delayms( uint16_t millis )
- {
- while ( millis )
- {
- _delay_ms( 1 );
- millis--;
- }
- }
- void blink_red()
- {
- PORTB = 0b00000010;
- _delay_ms(10);
- PORTB = 0b00000000;
- _delay_ms(10);
- }
- void command_send( char *buf, int len )
- {
- int i = 0;
- for( i=0; i<len; i++ )
- {
- blink_red();
- UDR0 = buf[i];
- }
- }
- int main( void )
- {
- // Init serial
- DDRD = 0b01101000;
- DDRB = 0xFF;
- UBRR0 = ((( F_CPU / (BAUD * 16UL ))) - 1);
- UCSR0B = _BV( RXEN0 ) | _BV( TXEN0 );
- UCSR0C = 0b00000110;
- UCSR0B |= ( 1 << RXCIE0 );
- sei();
- command_send( "AT+CWJAP="XXXXXXX","XXXXXXXXXX"rn", 32 );
- _delay_ms( 15000 );
- while( 1 )
- {
- command_send( "AT+CIPSTART="TCP","111.111.111.111",667rn", 41 );
- char data[] = { "AT+CIPSEND=10rn1111122222" };
- _delay_ms( 30 * 1000 );
- command_send( data , 25 );
- _delay_ms( 30 * 1000 );
- command_send( "AT+CIPCLOSErn", 13 );
- _delay_ms( 30 * 1000 );
- }
- return 0;
- }
- ISR( USART_RX_vect )
- {
- char ReceivedByte;
- ReceivedByte = UDR0;
- buffer[ received ] = ReceivedByte;
- received++;
- }
- CC=/usr/bin/avr-gcc
- MEGA=328p
- CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega$(MEGA)
- OBJ2HEX=/usr/bin/avr-objcopy
- PROG=/usr/bin/avrdude
- TARGET=esp8266
- DEVICE=/dev/ttyACM0
- program : $(TARGET).hex
- $(PROG) -c avrispv2 -p m$(MEGA) -P $(DEVICE) -e -B 2.0 -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m
- $(PROG) -c avrispv2 -p m$(MEGA) -P $(DEVICE) -U flash:w:$(TARGET).hex
- %.obj : %.o
- $(CC) $(CFLAGS) $< -o $@
- %.hex : %.obj
- $(OBJ2HEX) -R .eeprom -O ihex $< $@
- clean :
- rm -f *.hex *.obj *.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement