Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. // Connect to WIFI
  2. AT+CWJAP="MYNET","MYPASSWORD"rn
  3.  
  4. /*
  5. * Loop
  6. *
  7. * Open TCP connection
  8. * Send 10 bytes
  9. * Close TCP Connection
  10. */
  11. AT+CIPSTART="TCP","104.111.111.111",667rn
  12. AT+CIPSEND=10rn1111122222rn
  13. AT+CIPCLOSErn
  14.  
  15. Ncat: Connection from 111.111.111.111:11672.
  16. 1111122222
  17. Ncat: Connection from 111.111.111.111:35756.
  18. 2AT+CIPCLO1111122222
  19. Ncat: Connection from 111.111.111.111:8784.
  20. 1111122222
  21. Ncat: Connection from 111.111.111.111:63288.
  22. 1111122222
  23. Ncat: Connection from 111.111.111.111:28498.
  24. 1111122222
  25. Ncat: Connection from 111.111.111.111:33319.
  26. 1111122222
  27. Ncat: Connection from 111.111.111.111:35146.
  28. 1111122222
  29. Ncat: Connection from 111.111.111.111:34454.
  30. 1111122222
  31. Ncat: Connection from 111.111.111.111:33916.
  32. 1111122222
  33. Ncat: Connection from 111.111.111.111:37095.
  34. 1111122222
  35. Ncat: Connection from 111.111.111.111:12652.
  36. 1111122222
  37. Ncat: Connection from 111.111.111.111:61951.
  38. 1111122222
  39. Ncat: Connection from 111.111.111.111:27051.
  40. 1111122222
  41. Ncat: Connection from 111.111.111.111:61870.
  42. 111122222A1111122222
  43. Ncat: Connection from 111.111.111.111:38063.
  44. 1111122222
  45. Ncat: Connection from 111.111.111.111:32270.
  46.  
  47. 111122222A1111122222
  48. 2AT+CIPCLO1111122222
  49.  
  50. 1. The data I receive from ESP8266 is for the most part 0x00, so I can't read and process the responses.
  51. 2. Not totally sure if this is correct: UBRR0 = ((( F_CPU / (BAUD * 16UL ))) - 1);
  52. 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.
  53.  
  54. #include <avr/io.h>
  55. #include <util/delay.h>
  56. #include <avr/interrupt.h>
  57. #include <string.h>
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <util/delay.h>
  61. #include <avr/interrupt.h>
  62.  
  63. #define F_CPU 8000000UL
  64. #define BAUD 9600
  65.  
  66. char buffer[ 70 ];
  67. int received = 0;
  68.  
  69. void delayms( uint16_t millis )
  70. {
  71. while ( millis )
  72. {
  73. _delay_ms( 1 );
  74. millis--;
  75. }
  76. }
  77.  
  78. void blink_red()
  79. {
  80. PORTB = 0b00000010;
  81. _delay_ms(10);
  82. PORTB = 0b00000000;
  83. _delay_ms(10);
  84. }
  85.  
  86.  
  87. void command_send( char *buf, int len )
  88. {
  89. int i = 0;
  90.  
  91. for( i=0; i<len; i++ )
  92. {
  93. blink_red();
  94. UDR0 = buf[i];
  95. }
  96. }
  97.  
  98. int main( void )
  99. {
  100. // Init serial
  101. DDRD = 0b01101000;
  102. DDRB = 0xFF;
  103. UBRR0 = ((( F_CPU / (BAUD * 16UL ))) - 1);
  104. UCSR0B = _BV( RXEN0 ) | _BV( TXEN0 );
  105. UCSR0C = 0b00000110;
  106. UCSR0B |= ( 1 << RXCIE0 );
  107.  
  108. sei();
  109.  
  110. command_send( "AT+CWJAP="XXXXXXX","XXXXXXXXXX"rn", 32 );
  111. _delay_ms( 15000 );
  112.  
  113. while( 1 )
  114. {
  115. command_send( "AT+CIPSTART="TCP","111.111.111.111",667rn", 41 );
  116. char data[] = { "AT+CIPSEND=10rn1111122222" };
  117. _delay_ms( 30 * 1000 );
  118. command_send( data , 25 );
  119. _delay_ms( 30 * 1000 );
  120. command_send( "AT+CIPCLOSErn", 13 );
  121. _delay_ms( 30 * 1000 );
  122. }
  123.  
  124. return 0;
  125. }
  126.  
  127. ISR( USART_RX_vect )
  128. {
  129. char ReceivedByte;
  130.  
  131. ReceivedByte = UDR0;
  132. buffer[ received ] = ReceivedByte;
  133.  
  134. received++;
  135. }
  136.  
  137. CC=/usr/bin/avr-gcc
  138. MEGA=328p
  139. CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega$(MEGA)
  140. OBJ2HEX=/usr/bin/avr-objcopy
  141. PROG=/usr/bin/avrdude
  142. TARGET=esp8266
  143. DEVICE=/dev/ttyACM0
  144.  
  145. program : $(TARGET).hex
  146. $(PROG) -c avrispv2 -p m$(MEGA) -P $(DEVICE) -e -B 2.0 -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m
  147. $(PROG) -c avrispv2 -p m$(MEGA) -P $(DEVICE) -U flash:w:$(TARGET).hex
  148.  
  149. %.obj : %.o
  150. $(CC) $(CFLAGS) $< -o $@
  151.  
  152. %.hex : %.obj
  153. $(OBJ2HEX) -R .eeprom -O ihex $< $@
  154.  
  155. clean :
  156. rm -f *.hex *.obj *.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement