I have a SIM800L Module connected to my arduino Nano. I want to open a TCP connection from the sim800l module to my own server and send a text string. The connection is working however I am not able to send text, because there is an issue with the arduino write() function I think... Below is the code I am trying to execute. Right after the message is sent, I need to send the stop value 0x1A (byte 26) to tell the sim800l module that the message end is reached and to send out the message. My problem is, that it is not working in the arduino IDE and I don't know why.

My arduino code:

#include <SoftwareSerial.h>

#define SIM800_TX_PIN 8
#define SIM800_RX_PIN 7

SoftwareSerial serialSIM800(SIM800_TX_PIN, SIM800_RX_PIN);

void setup() {


serialSIM800.println("AT+CIPSTART=\"TCP\",\"IP-ADRESS-HERE\",\"9999\""); //connection works


serialSIM800.print("TEXT MESSAGE HERE");



void loop() {

On my server I am running this python script that opens a socket:

import socket
import sys

HOST = ''   # all available interfaces
PORT = 9999 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
  s.bind((HOST, PORT))
except socket.error as msg:
  print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]

print 'Socket bind complete'

#Start listening on socket
print 'Socket now listening'

#now keep talking with the client
while 1:
  #wait to accept a connection - blocking call
  conn, addr = s.accept()
  print 'Connected with ' + addr[0] + ':' + str(addr[1])
  data = conn.recv(1024)
  print len(data)
  print data

Once I execute this, I see the connection is working because "Connected with IP:PORT" is printed on my console. However right after that "len(data)" is printed (0) and "data" is an empty string. I even upped the delay from 500 to 5000, still same result.

However, if I leave the arduino IDE and send the message using the program "HTerm", it is working! In HTerm I typed in the text message and hit enter. After that I switched from ascii to hex mode (there is a checkbox) and I just typed 1A and sent it. That way it worked. Anybody can help me? Why is it not working @arduino?

  • After typing 1A into HTerm hex mode, did you hit ENTER? – Roberto Lo Giacco Sep 8 '16 at 21:15
  • Yes I hit Enter and it worked in HTerm. – Chris Sep 8 '16 at 21:25

Replace serialSIM800.write(26); with serialSIM800.write(0x1A);, also change serialSIM800.print("TEXT MESSAGE HERE"); with a println or add a carriage return \n.

  • good idea. I already tested this. serialSIM800.write(0x1A) didn't help and I even replaced all println with print and added a \n to the end of each string. That all didnt work... even with \r\n it didnt work. – Chris Sep 8 '16 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.